GitHub Actions by Example: Outputs

Data can be shared between jobs and steps.

name: outputs
on:
  push:
jobs:
  job1:
    runs-on: ubuntu-latest
    steps:
      -
        name: Do Work

Create outputs for a step by writing to stdout in the format of ::set-output name=<name>::<value>. A step can have multiple outputs.

        run: |
          echo '::set-output name=FAV_NUMBER::3'
          echo '::set-output name=FAV_COLOR::blue'          

Steps that create outputs must have unique ids.

        id: abc
      -
        name: Read output

Use the steps context variable and step id to get the value

        run: |
          echo "${{steps.abc.outputs.FAV_NUMBER}}"
          echo "${{steps.abc.outputs.FAV_COLOR}}"          

Create outputs for a job which will be available to other jobs that needs it (see Job Ordering). You can include output from steps that ran for the job.

    outputs:
      fav-animal: tiger
      fav-number: ${{steps.abc.outputs.FAV_NUMBER}}
  job2:
    runs-on: ubuntu-latest
    needs: job1
    steps:

Use context expressions to grab outputs from a job included in needs (see Job Ordering)

      - run: |
        echo "${{needs.job1.outputs.fav-animal}}"
        echo "${{needs.job1.outputs.fav-number}}"        

Next example: Context Variables