Skip to content
Latchkey

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_ENV

Common 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

  1. Wrap the value in KEY<<DELIM ... DELIM with a delimiter not present in the content.
  2. Use a random/unique delimiter for untrusted content.
  3. 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

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →