Skip to content
shellhacks.dev
CI/CD

Set an output in GitHub Actions

Pass a value to a later step by appending name=value to the file in GITHUB_OUTPUT. The old set-output command is deprecated, and multiline values need a delimiter.

1 min read
Summarize in AI

One step computes a version and a later step needs it, and the ::set-output command that every old guide shows is retired.

Shell
export GITHUB_OUTPUT=$(mktemp)
echo "version=1.4.2" >> "$GITHUB_OUTPUT"
{
  echo "notes<<EOF_NOTES"
  printf 'first change\nsecond change\n'
  echo "EOF_NOTES"
} >> "$GITHUB_OUTPUT"
cat "$GITHUB_OUTPUT"
Text
version=1.4.2
notes<<EOF_NOTES
first change
second change
EOF_NOTES

The runner gives each step the path of a file in GITHUB_OUTPUT, and after the step finishes it reads name=value lines from it, as the workflow commands reference explains. Here a temporary file stands in for the runner's, so the output is exactly what the runner would parse. A later step reads the first value as steps.ID.outputs.version, when the step has id: ID.

A value that spans lines needs the name<<DELIMITER form shown, and the delimiter must not appear in the value. A random delimiter is safer when the value comes from untrusted input. The deprecated ::set-output command is no longer processed, and a step with no id has no outputs that others can name.

Share

More snippets

CI/CD

Check what changed in a pull request

List the files a pull request changed with git diff --name-only origin/main...HEAD. Three dots compare against the merge base, and a shallow checkout cannot do it.

2 min read
CI/CD

Print a warning annotation

Print ::warning file=...,line=...::message from a step to show an annotation on the run and in the pull request diff. Newlines in the text must be encoded.

1 min read
CI/CD

Run a script from the repo

Run a repository script from a workflow with run: ./script.sh only if Git stores it as executable. Otherwise the step fails with Permission denied, status 126.

2 min read

Get new posts by email

One email when a new post is published. No spam.

Unsubscribe in one click. No spam, ever.