GitHub Action报错:workflow defaults无法识别命名值'inputs'
问题原因
GitHub Actions 的 defaults.run 配置块属于工作流全局默认配置阶段,不支持引用通过 workflow_call 传入的 inputs 变量。而 concurrency 配置能正常使用 inputs,是因为它的变量访问时机和权限与 defaults 不同。
解决方案
你可以通过以下两种方式替代 defaults.run 的配置:
方式1:在每个 run 步骤中直接指定工作目录
将工作目录配置移到每个需要执行的 run 步骤里,直接引用 inputs.service:
name: Test CI on: workflow_call: inputs: service: description: Service to run CI for required: true type: string concurrency: group: ${{ inputs.service }}-test-ci-${{ github.head_ref || github.ref }} cancel-in-progress: true jobs: test: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v4 - name: Install dependencies run: npm install working-directory: ./services/${{ inputs.service }} - name: Run tests run: npm test working-directory: ./services/${{ inputs.service }}
方式2:使用作业级环境变量统一管理路径
如果不想重复编写工作目录路径,可以在作业的 env 块中定义路径(作业级 env 支持引用 inputs),后续步骤直接引用环境变量:
name: Test CI on: workflow_call: inputs: service: description: Service to run CI for required: true type: string concurrency: group: ${{ inputs.service }}-test-ci-${{ github.head_ref || github.ref }} cancel-in-progress: true jobs: test: runs-on: ubuntu-latest env: SERVICE_DIR: ./services/${{ inputs.service }} steps: - name: Checkout code uses: actions/checkout@v4 - name: Install dependencies run: npm install working-directory: ${{ env.SERVICE_DIR }} - name: Run tests run: npm test working-directory: ${{ env.SERVICE_DIR }}
内容的提问来源于stack exchange,提问作者Kevin Kelly
相关产品推荐
相关产品推荐

