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

GitHub Actions复用工作流传参:'uses'/'with'报错原因及解决

问题原因及解决方法

错误原因

你在同一个job中同时指定了runs-on和uses字段,这违反了GitHub Actions的语法规则:

  • 当用uses调用可复用工作流作为独立job时,该job的运行环境(如runs-on)应由可复用工作流本身定义,不能在当前job中重复声明。
  • 若要在现有job内调用可复用工作流的步骤,uses必须嵌套在steps字段下,不能放在job的顶级层级。

正确调用方式

方式1:直接调用可复用工作流作为独立job

删除当前job中的runs-on字段,让可复用工作流定义job的运行配置:

jobs:
  my-job:
    uses: my-org/my-repo/.github/workflows/reusable.yml@v1.0.0
    with:
      app-command: synth
      app-args: -c xpiKeyPath=/my/apikey

方式2:在现有job的步骤中调用可复用工作流

将uses和with放到steps节点下,保留runs-on:

jobs:
  my-job:
    runs-on: ubuntu-latest
    steps:
      - name: 执行可复用工作流步骤
        uses: my-org/my-repo/.github/workflows/reusable.yml@v1.0.0
        with:
          app-command: synth
          app-args: -c xpiKeyPath=/my/apikey

正确传递参数的前提

要成功传递参数,必须确保可复用工作流(reusable.yml)中已经提前定义了对应的输入参数,示例如下:

name: 可复用工作流
on:
  workflow_call:
    inputs:
      app-command:
        type: string
        required: true  # 根据需求设置是否必填
      app-args:
        type: string
        required: false

在可复用工作流内部,你可以通过${{ inputs.app-command }}和${{ inputs.app-args }}来引用这些传递过来的参数。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.21 01:30:11