You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

GitHub Action工作流YAML语法错误:第14行runs-on报错求助

GitHub Workflow YAML语法错误(第14行)

用户提供的YAML配置文件如下:

# This is a basic workflow to help you get started with Actions

name: TestWorkflowGithub

# Controls when the workflow will run
on:
  # Triggers the workflow on push or pull request events but only for the "main" branch
  pull_request:
    branches:
    - 'testbranch/**'
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # The type of runner that the job will run on
  runs-on: ubuntu-latest

  # Steps represent a sequence of tasks that will be executed as part of the job
  steps:
    - name: Checkout the code
      uses: actions/checkout@v3

    - name: Install PMD
      run: |
        PMD_VERSION=`cat pmd/pmd-version.txt`
        wget https://github.com/pmd/pmd/releases/download/pmd_releases%2F6.54.0/pmd-bin-6.54.0.zip
        unzip pmd-bin-6.54.0.zip -d ~
        mv ~/pmd-bin-$6.54.0 ~/pmd
        ~/pmd/bin/run.sh pmd --version

    # Run PMD scandd
    - name: Run PMD scan
      run: ~/pmd/bin/run.sh pmd -d force-app -R pmd/ruleset.xml -f text

GitHub提示错误:You have an error in your yaml syntax on line 14,对应行内容为runs-on: ubuntu-latest,以下是问题分析与修复方案:


核心语法错误原因

jobs节点是字典结构,每个子节点必须是具体的Job名称,runs-on、steps这类Job属性需要嵌套在Job名称下方。你直接在jobs下写runs-on,违反了GitHub Workflow的YAML结构规范,导致解析失败。

修正后的完整配置

# This is a basic workflow to help you get started with Actions

name: TestWorkflowGithub

# Controls when the workflow will run
on:
  # Triggers the workflow on push or pull request events but only for the "main" branch
  pull_request:
    branches:
    - 'testbranch/**'
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # 定义Job名称(示例:pmd-code-scan)
  pmd-code-scan:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      - name: Checkout the code
        uses: actions/checkout@v3

      - name: Install PMD
        run: |
          PMD_VERSION=`cat pmd/pmd-version.txt`
          # 使用变量统一版本号,避免硬编码不一致
          wget https://github.com/pmd/pmd/releases/download/pmd_releases%2F${PMD_VERSION}/pmd-bin-${PMD_VERSION}.zip
          unzip pmd-bin-${PMD_VERSION}.zip -d ~
          mv ~/pmd-bin-${PMD_VERSION} ~/pmd
          ~/pmd/bin/run.sh pmd --version

      # Run PMD scan
      - name: Run PMD scan
        run: ~/pmd/bin/run.sh pmd -d force-app -R pmd/ruleset.xml -f text

额外优化说明

  1. 修复了shell脚本变量错误:原脚本定义PMD_VERSION却未使用,硬编码的$6.54.0会被shell解析为空的位置参数,现在统一用${PMD_VERSION}确保版本一致。
  2. 新增明确的Job名称pmd-code-scan,让配置结构更清晰,符合GitHub Workflow要求。

内容的提问来源于stack exchange,提问作者vt89

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.31 09:31:02