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

GitHub Actions如何引用上游版本作业的new_tag输出为Docker镜像打标签

GitHub Actions跨作业传递版本号解决方案

是的,你需要在version作业中显式声明outputs字段,才能将作业内步骤生成的输出传递给下游依赖作业。

GitHub Actions中不同作业默认运行在完全隔离的运行环境中,单个步骤的输出仅支持在当前作业的后续步骤中直接调用。如果要跨作业传递值,必须在作业层级将对应步骤的输出暴露为作业级别的公共输出。

具体修改点

  1. 为version作业新增outputs配置,关联版本生成步骤的输出值
  2. 修正docker作业中引用版本号的语法

修改后的完整配置如下:

jobs:
  setup:
    ...
  version:
    needs: [setup]
    runs-on: ubuntu-latest
    # 新增作业级输出声明,将步骤输出映射为作业输出
    outputs:
      new_tag: ${{ steps.autoversion.outputs.new_tag }}
    steps:
    - uses: actions/checkout@v2
      with:
        fetch-depth: '0'
    - name: Bump version and push tag
      uses: anothrNick/github-tag-action@1.26.0
      id: autoversion
      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        WITH_V: true
  sonar:
    ...
  anchore:
    ...
  docker:
    needs: [setup, version]
    steps:
      ...
      - name: Build and push
        uses: docker/build-push-action@v2
        with:
          context: .
          push: true
          # 修正引用语法,直接调用上游作业的公共输出
          tags: ansfire/flaskql:${{ needs.version.outputs.new_tag }}

语法说明

跨作业引用上游作业输出的标准规则为 ${{ needs.<上游作业名>.outputs.<作业输出名> }},不需要加入上游作业内的步骤ID。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.10 05:48:03