Store multiline string as base64 -w 0
job output, and consume in subsequent job.
jobs:
build:
runs-on: ubuntu-latest
outputs:
envFile: ${{ steps.tempEnvFile.outputs.envFile }}
steps:
... some step that builds .env file
- name: Cat .env file, encode and save as job output
id: tempEnvFile
run: |
ENV_FILE="$(cat .env | base64 -w 0)"
echo "envFile=$ENV_FILE" >> "$GITHUB_OUTPUT"
use-env-file:
needs: build
runs-on: ubuntu-latest
env:
envFile: ${{ needs.build.outputs.envFile }}
steps:
- name: Decode previous job output and save to file.
run: echo $envFile | base64 -d > .env
Github Actions ubuntu-latest
images supports base64 -w 0
, disabling column width restriction. This allows a single long string to be later decoded. Watch out for strings that are too long. Max size is 1Mb.
From base64
man page:
‘-w cols’
‘--wrap=cols’
During encoding, wrap lines after cols characters. This must be a positive number.
The default is to wrap after 76 characters. Use the value 0 to disable line wrapping altogether.
‘-d’
‘--decode’
Change the mode of operation, from the default of encoding data, to decoding data. Input is expected to be base64 encoded data, and the output will be the original data.