How to Set Output Values in Github Actions

#ci #github

This is the syntax for setting an output parameter in a Github Actions step.

echo "{name}={value}" >> "$GITHUB_OUTPUT"

Here’s an example of using this syntax in a workflow step.

- name: Expose the artifact path
  id: paths
  run: echo "artifact='app-setup.exe'" >> "$GITHUB_OUTPUT"

Here’s an example of using the output of a command as the value.

run: echo "artifact='$(yarn run artifact-path)'" >> "$GITHUB_OUTPUT"

And here is how you would access that output value in a later step.

- name: Later Step
  run: ./bin/codesign ${{ steps.paths.outputs.artifact }}

The syntax is steps.[step_id].outputs.[output_name].

It took me several attempts to discover this snippet on the Github Actions docs, so I decided to post it here.

Happy hacking.

Thanks for Reading

Email me your thoughts at kerrto-prevent-spam@hto-prevent-spamey.comto-prevent-spam or give me a mention on Mastodon.