Skip to content

Instantly share code, notes, and snippets.

@RupertBarrow
Last active January 13, 2025 01:25
Show Gist options
  • Save RupertBarrow/ef8be6b2051db0fa22447863942f9f93 to your computer and use it in GitHub Desktop.
Save RupertBarrow/ef8be6b2051db0fa22447863942f9f93 to your computer and use it in GitHub Desktop.
Github Actions - multiline output from a step, with GITHUB_OUTPUT

This is explained in the Github Actions docs, but is not explicitly clear : https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-output-parameter

It is explained in this issue : github/docs#21529

Here is my example :

runs:
  using: "composite"
  steps:
    - name: Run command
      id: command
      shell: bash
      run: |
        res=$( ls -al )

        echo "myresult<<EOF" >> "$GITHUB_OUTPUT"
        echo $res >> "$GITHUB_OUTPUT"
        echo "EOF" >> "$GITHUB_OUTPUT"

    - name: DEBUG
      if: ${{ always() }}
      run: |
        echo "result = ${{ steps.command.outputs.myresult }}"

In this example :

  • the result of ls is stored in the res variable
  • this value is echoed out into GITHUB_OUTPUT over several lines
  • the first line holds the name of the output variable myresult
  • the output is available in the myresult output of the command step
  • the output is on one single line, so that is easy to use if it is JSON, for example
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment