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

Github Actions的github-script无法获取可复用工作流输入值

解决复用GitHub Actions工作流无法获取输入参数的问题

问题出在你没有将工作流级别的base_os输入传递给github-script步骤的参数。core.getInput()方法读取的是当前步骤with块中定义的参数,而非工作流全局的inputs。

修改你的复用工作流,在github-script步骤的with块中添加参数传递:

on:
  workflow_call:
    inputs:
      base_os:
        description: "The base os"
        type: string
        required: true


jobs:
  upstream-image-name:
    name: get the image name for the upstream image
    runs-on: ubuntu-latest

    steps:

      - name: get upstream image name
        id: upstream-image-name-step
        uses: actions/github-script@v6
        with:
          result-encoding: string
          # 将工作流输入传递给步骤参数
          base_os: ${{ inputs.base_os }}
          script:
            console.log('base_os =', core.getInput('base_os'))

修改后,github-script步骤就能通过core.getInput('base_os')读取到调用工作流时传入的debian值了。

你也可以选择直接在脚本中引用工作流输入,跳过步骤参数传递:

script:
  console.log('base_os =', '${{ inputs.base_os }}')

这种方式不需要修改with块,同样能输出正确的参数值。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.09 02:35:28