I'm not sure if that was a hack or undocumented feature, but I can find it now in the GitHub Actions docs.
But in the past, I needed to copy a short multiline file between GitHub Actions jobs, and I didn't want to bother with extra steps of stash/unstash stuff, so I found that you can define a multiline GitHub Actions variable!
It was as easy as this:
jobs:
job1:
runs-on: ubuntu-latest
steps:
- name: Set multiline value in bash
run: |
# The curly brackets are just Bash syntax to group commands
# and are not mandatory.
{
echo 'JSON_RESPONSE<<EOF'
cat my-file.json
echo EOF
} >> "$GITHUB_OUTPUT"
Of course, you need to be sure that the delimiter EOF doesn't occure within the value.
Then you can call that again as:
[...]
job2:
needs: job1
runs-on: ubuntu-latest
steps:
- name: Get multiline value in bash
run: |
echo "${{ needs.job1.outputs.JSON_RESPONSE }}"
That's it! Enjoy! ♾️