Search code examples
github-actionsgithub-actions-artifacts

Reference output from previous job GH Actions


I am attempting to use GitHub Actions for a complete pipeline, including automatic SemVer versioning (using tags) that I would then like to consume after building my Docker image to tag it with the current version. This is the action that I am using to bump the version, which should have a new_tag output but I cannot reference it, this is what I am trying:

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/[email protected]
      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 }}

From what I have read using the needs key is supposed to allow one job to access upstream jobs but I cannot get it to access this. Do I need an outputs key in the version stage? Thanks!


Solution

  • Look into this answer, you need to define the outputs in the job creating the outputs, i.e.

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