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

复用GitHub Action工作流新添加输入值始终为空的问题

问题描述

我正尝试完成一项简单操作:向复用工作流的输入参数传递值。我此前在同一仓库中成功实现过该操作,且原有逻辑仍正常运行,但现在为任意工作流新增的输入参数都无法获取到传入值。

复用工作流代码

on:
  workflow_call:
    inputs:
        branch-to-build:
          # do not use branch as name as it will be master in a scheduled run
          type: string
          description: 'Branch to checkout, build and publish'
          required: false
          default: 'dev'
        tag-to-apply:
          type: string
          description: 'Tag to apply to the images'
          required: false
          default: 'nightly-dev'

jobs:
  tag:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
        with:
          ref: ${{ github.event.inputs.branch-to-build }}

调用工作流代码

jobs:
  nightly-build-dev:
    uses: ./.github/workflows/reusable.yml
    with:
        branch-to-build: 'dev'
        tag-to-apply: 'nightly-dev'
    secrets: inherit

当我通过GitHub UI触发调用工作流时,branch-to-build的值始终为空,既无法获取传入的dev,也无法使用默认值dev。我尝试使用inputs.branch-to-build也无济于事,请问我忽略了什么?


解决方案

1. 修正复用工作流的输入引用方式

在workflow_call触发的复用工作流中,必须通过inputs上下文直接访问参数,而非github.event.inputs。将checkout步骤的引用改为:

ref: ${{ inputs.branch-to-build }}

github.event.inputs仅适用于workflow_dispatch、workflow_run等直接触发的事件,不适用于复用工作流的参数传递。

2. 确认复用工作流的变更已提交

如果修改了复用工作流但未将变更推送到仓库,GitHub Actions会继续执行旧版本的工作流文件,导致参数无法正常读取。请确保.github/workflows/reusable.yml的最新变更已提交并推送到远程仓库。

3. 补充调用工作流的触发配置

若通过GitHub UI手动触发调用工作流,调用工作流必须配置workflow_dispatch事件,否则无法在UI中找到触发入口。补充调用工作流的on配置:

on:
  workflow_dispatch:

jobs:
  nightly-build-dev:
    uses: ./.github/workflows/reusable.yml
    with:
        branch-to-build: 'dev'
        tag-to-apply: 'nightly-dev'
    secrets: inherit

4. 验证参数与路径的正确性

  • 确认调用工作流中传递的参数名(如branch-to-build)与复用工作流的定义完全一致,包括大小写、连字符等细节。
  • 确认复用工作流的路径(./.github/workflows/reusable.yml)拼写正确,路径需相对于仓库根目录。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.13 14:25:11