上一个作业 GH Actions 的参考输出

Reference output from previous job GH Actions

我正在尝试对完整的管道使用 GitHub 操作,包括自动 SemVer 版本控制(使用标签),然后我想在构建我的 Docker 图像后使用它来标记它当前版本。这是我用来修改版本的 action,它应该有一个 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 键应该允许一个作业访问上游作业,但我无法让它访问它。 version 阶段需要 outputs 键吗?谢谢!

查看此 ,您需要在创建输出的作业中定义 outputs,即

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

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