workflow

env:

Defines environment variables for a scope. Declared at the workflow, job, or step level and read back via the `env` context or as real environment variables inside `run:` scripts.

env:
  KEY: value

Common values / subkeys

Value / Subkey Purpose
workflow-level env Defaults for every job in the file
job-level env Defaults for every step in a job
step-level env Only for that step's run
${{ env.NAME }} Read the value in an expression
$GITHUB_ENV Append `KEY=value` here to expose to later steps

Examples

env:
  NODE_ENV: production
  API_URL: https://api.example.com

Workflow-wide defaults

steps:
  - run: echo "$MY_VAR"
    env:
      MY_VAR: ${{ secrets.TOKEN }}

Injecting a secret via env avoids expression-injection in the script body

- run: echo "BUILD_ID=$GITHUB_RUN_ID" >> "$GITHUB_ENV"
- run: echo ${{ env.BUILD_ID }}

Persist a value into env for later steps

- if: env.APP == 'web'
  run: echo web build

Guard a step on an env value

Gotcha

Inside `run:` reference values as `$VAR` (bash) or `$env:VAR` (pwsh) — a bare `export FOO=...` in a shell is NOT visible to later steps; write to `$GITHUB_ENV` instead.

Related keywords

← All GitHub Actions syntax · Git commands · Cron syntax