首页 > 解决方案 > 上一个作业的参考输出 GH Actions

问题描述

我正在尝试将 GitHub Actions 用于完整的管道,包括自动 SemVer 版本控制(使用标签),然后我想在构建我的 Docker 映像后使用它以使用当前版本对其进行标记。这是我用来提升版本的操作,它应该有一个 new_tag 输出但我无法引用它,这就是我正在尝试的:

jobs:
  setup:
    ...
  version:
    needs: [setup]
    runs-on: ubuntu-latest
    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.autoversion.outputs.new_tag }}

从我所阅读的内容来看,使用该needs密钥应该允许一项工作访问上游工作,但我无法让它访问它。我需要在舞台上使用outputs钥匙吗?version谢谢!

标签: github-actionsgithub-actions-artifacts

解决方案


查看这个答案,您需要outputs在创建输出的作业中定义,即

jobs:
  version:
    [...]
    outputs:
      new_tag: ${{ steps.autoversion.outputs.new_tag }}

  docker:
    [...] tags: ansfire/flakql:${{ needs.version.outputs.new_tag }}

推荐阅读