Github actions and output variables

Output variables can be powerful and frustrating 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
.
Get output values between steps
This is pretty simple just call
Syntax receive step output: ${{steps.<StepId>.outputs.<VariableName>}}
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>}}
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>}}
Written by Yuna Morgenstern Tech Lead @ Europace