Skip to content
Latchkey

What Is the GITHUB_ENV File in GitHub Actions?

GITHUB_ENV points to a file. Writing NAME=value to it sets an environment variable for all later steps in the job.

A variable you export in one step is gone in the next, because each run is a fresh shell. The GITHUB_ENV file is GitHub's mechanism for persisting environment variables across steps in a job.

What it is

An environment variable holding a file path. Appending NAME=value lines to that file tells GitHub to set those variables in the environment of every subsequent step.

Persisting a variable
steps:
  - run: echo "BUILD_ID=${{ github.run_id }}" >> "${GITHUB_ENV}"
  - run: echo "Building $BUILD_ID"

How it works

After a step finishes, GitHub reads the appended lines and injects them as environment variables for the remaining steps. Multiline values use a heredoc-style delimiter.

GITHUB_ENV vs GITHUB_OUTPUT

GITHUB_ENV sets environment variables read as $NAME; GITHUB_OUTPUT sets step outputs read via the steps context. Use env for shell variables, outputs for expression data.

Why it matters

It is the supported way to share state between steps, replacing the deprecated ::set-env:: command. Knowing it avoids the classic "my exported variable disappeared" confusion.

Related concepts

It parallels GITHUB_OUTPUT for step outputs and GITHUB_STEP_SUMMARY for job summaries, all special files steps append to.

Key takeaways

  • GITHUB_ENV is a file path for setting env vars.
  • Appended NAME=value lines persist to later steps.
  • It replaces the deprecated ::set-env:: command.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →