Skip to content

Outputs

In a workflow, each job run in its own separate execution environment. But, sometime, you would like to get some information from a job you depend on.

Basic ordering is offered by the needs section. Once a job depends on another, it can access the outputs produced by the job(s) it depends on, through contexts.

Hello World

Steps can produce outputs through workflow commands. Outputs are name/value pairs and hold strings.

Workflow commands are printed in the standard output stream of an execution environment. For more information on defining workflow commands, see “Workflow commands for OpenTestFactory Orchestrator.”

The set-output workflow command is as follows:

::set-output name=xxx::yyyy

The following step will create an output named test of value hello:

steps:
- id: step1
  run: echo "::set-output name=test::hello"

A step can produce any number of outputs:

steps:
- id: step1
  run: |
    echo "::set-output name=foo::foo foo"
    echo "::set-output name=bar::bar baz"

A job can collect and expose the outputs produced by the steps it contains to its dependent jobs. Here, the job job1 will expose an output1 output that will have a value of hello, and an output2 output that will have a value of something else:

job1:
  outputs:
    output1: ${{ steps.step1.outputs.test }}
    output1: something else
  steps:
  - id: step1
    run: echo "::set-output name=test::hello"

Other jobs that depend on this job1 job can then access those outputs:

metadata:
  name: Using outputs from a previous job
jobs:
  job1:
    runs-on: linux
    # Map a step output to a job output
    outputs:
      output1: ${{ steps.step1.outputs.test }}
      output2: ${{ steps.step2.outputs.test }}
    steps:
    - id: step1
      run: echo "::set-output name=test::hello"
    - id: step2
      run: echo "::set-output name=test::world"
  job2:
    runs-on: linux
    needs: job1
    steps:
    - run: echo ${{needs.job1.outputs.output1}} ${{needs.job1.outputs.output2}}

This should echo ‘hello world’ in the execution environment in which job2 runs.