Github actions and output variables

Published On: 9. September 2022|Categories: Tech|
kaleidico-3V8xo5Gbusk-unsplash

Output variables can be powerful and frust­rating at the same time. This simple how to, can save you ages of try and error.

What are output variables

Output variables are like return values of a step which can be used in all down streams like jobs, reusable workflows and more. See GitHub Workflow Job Output Example Accessing these outputs can be pretty challenging as it depends on the context in which you are.

Creating an output

Creating an output is pretty simple made by an echo.
The output from a step will be later referenced by its id.

Syntax define step output: echo "<VariableName>=my variable value" >> $GITHUB_OUTPUT.

Copy to Clipboard

Get output values between steps

This is pretty simple just call

Syntax receive step output: ${{steps.<StepId>.outputs.<VariableName>}}

Copy to Clipboard

Get output values between jobs

Now the outputs needs to be defined also on the job level.
Plus the jobs needs to be connected by adding needs: my_job

Syntax define job output: ${{steps.<StepId>.outputs.<VariableName>}}
Syntax receive job output: ${{needs.<JobId>.outputs.<VariableName>}}

Copy to Clipboard

Get output variables between workflows

Yes this is another context….

Syntax define job output: ${{steps.<StepId>.outputs.<VariableName>}}
Syntax define workflow output: ${{jobs.<JobId>.outputs.<VariableName> }}
Syntax receive job output: ${{needs.<JobId>.outputs.<VariableName>}}

Copy to Clipboard

Written by Yuna Morgen­stern Tech Lead @ Europace