GitHub Actions — Output Parameters

Pavel Saman
2 min readDec 21, 2022

--

GitHub has changed how output parameters should be written, let’s see the new syntax.

I’ve done a lot of work on CI/CD pipelines over last couple of months and this changed at some point. GitHub then started posting deprecation warning messages into Annotations on the Summary page. I can still see a lot of places and projects where the old syntax is used, which makes the Summary page harder to use due to all the warnings.

When you wanted to output a certain value, the old syntax was this:

- id: env-setup
run: |
echo "::set-output name=env_token::production"
- run: |
echo "${{ steps.env-setup.outputs.env_token }}"

I must say that the syntax is a bit clumsy for such a simple task. I never got it right on the first try and GitHub docs were almost always open somewhere in my browser :D

Fortunately, GitHub than came up with a new syntax:

- id: env-setup
run: |
echo "env_token=production" >> $GITHUB_OUTPUT
- run: |
echo "${{ steps.env-setup.outputs.env_token }}"

I don’t have a problem remembering this, so I became way more efficient as well :)

You sometimes need to set multiple values in some preparatory step, so you can write it like so:

- id: env-setup
run: |
{
"env_token=production"
"env_domain=example.com"
} >> $GITHUB_OUTPUT
- run: |
echo "${{ steps.env-setup.outputs.env_token }}"
echo "${{ steps.env-setup.outputs.env_domain }}"

Nice and short.

My recommendation for such preparatory tasks is to output the variables and their values into a step summary as well:

- id: env-setup
run: |
{
"env_token=production"
"env_domain=example.com"
} >> $GITHUB_OUTPUT

{
echo "### Workflow variables"
echo "| Variable | Value |"
echo "| ---------- | ----------- |"
echo "| env_token | $env_token |"
echo "| env_domain | $env_domain |"
} >> $GITHUB_STEP_SUMMARY
- run: |
echo "${{ steps.env-setup.outputs.env_token }}"
echo "${{ steps.env-setup.outputs.env_domain }}"

This will create a nice Markdown table on the Summary page so no one needs to go into logs and dig through them to look up what variables the workflow used.

Missing step summary has been one of the most obvious and constant pains I’ve come across during my work in various repositories. Really, it’s such a small thing created in 5 minutes, but it can save a huge amounts of time and mental energy.

--

--