GitHub Actions heredoc to GITHUB_ENV multiline failed
Writing a multiline value to \${GITHUB_ENV} requires a heredoc with a unique delimiter. A missing delimiter, or one that appears inside the value, corrupts the environment-file format and fails the step.
What this error means
A step writing a multiline env var fails parsing the environment file, or downstream steps see a truncated/garbled value.
github-actions
Error: Invalid format ' "nested": true,'
while reading GITHUB_ENVCommon causes
Missing heredoc delimiter
Writing key=multiline value without a heredoc breaks the env-file parser.
Delimiter collides with the value
If the chosen delimiter appears in the content, the block terminates early.
How to fix it
Use a unique heredoc delimiter
- Wrap the value in KEY<<DELIM ... DELIM with a delimiter not present in the content.
- Use a random/unique delimiter for untrusted content.
- Apply the same pattern for GITHUB_OUTPUT multiline values.
.github/workflows/ci.yml
- run: |
{
echo 'CONFIG<<EOF'
cat config.json
echo 'EOF'
} >> "${GITHUB_ENV}"How to prevent it
- Always use heredoc delimiters for multiline GITHUB_ENV/GITHUB_OUTPUT writes.
- Choose delimiters that cannot appear in the value.
Related guides
GitHub Actions multiline GITHUB_OUTPUT broken without heredocFix a GitHub Actions multiline step output that is truncated - multiline GITHUB_OUTPUT values need a heredoc…
GitHub Actions env var with special characters not escapedFix a GitHub Actions env value containing special characters that breaks the shell - quoting and escaping are…
GitHub Actions save-state deprecated (use GITHUB_STATE)Fix the GitHub Actions save-state deprecation - write state to the GITHUB_STATE file instead of the ::save-st…