先前作业 GH 操作的参考输出

use*_*147 0 github-actions github-actions-artifacts

我正在尝试使用 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 }}
Run Code Online (Sandbox Code Playgroud)

根据我所读到的内容,使用needs密钥应该允许一个作业访问上游作业,但我无法让它访问它。outputs我在舞台上需要钥匙吗version?谢谢!

Luc*_*ppa 5

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

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

  docker:
    [...] tags: ansfire/flakql:${{ needs.version.outputs.new_tag }}
Run Code Online (Sandbox Code Playgroud)