Search code examples
githubgithub-actions

How to set and change GitHub workflow output


I'm trying to figure out how to set an output, change the output, then use it it the following job. I've tried making this as simple as possible yet the last echo returns true. The documentation doesn't provide examples so any insight or advice would be great.

  job-1:
    runs-on: ubuntu-latest
    outputs:
      compare: true
    steps:
      - name: set output
        run: |
          echo "::set-output name=compare::false"
  job-2:
    runs-on: ubuntu-latest
    # require the first job to have ran
    needs: compare
    steps:
      - name: echo job-1 compare output
        run: |
          echo ${{ needs.job-1.outputs.compare }}

Solution

  • I learned you have to declare the value of compare in run and use an id

     job-1:
        runs-on: ubuntu-latest
        outputs:
          compare: ${{ steps.job_id.outputs.compare}}
        steps:
          - name: set output to false
            id: job_id
            run: |
              echo "::set-output name=compare::false"
      job-2:
        runs-on: ubuntu-latest
        # require the first job to have ran
        needs: compare
        steps:
          - name: echo job-1 compare output
            run: |
              echo ${{ needs.job-1.outputs.compare }}