Skip to content
Latchkey

How to Set a Global Environment Variable for the Whole Workflow in GitHub Actions

A top-level env: block sets variables visible to every job and step in the workflow.

Declare env: at the workflow root for variables shared everywhere, at the job level for one job, or at the step level for one step. Inner scopes override outer ones.

Steps

  • Add a top-level env: map above jobs:.
  • Reference $NAME or ${{ env.NAME }} anywhere in the workflow.
  • Override per job or per step by declaring env: there.

Workflow

.github/workflows/ci.yml
env:
  NODE_ENV: test
  CI: 'true'
jobs:
  build:
    runs-on: ubuntu-latest
    env:
      LOG_LEVEL: debug
    steps:
      - run: echo "env=$NODE_ENV level=$LOG_LEVEL"

Gotchas

  • Static env: cannot reference secrets; pass those via step env: instead.
  • A value written to $GITHUB_ENV at runtime overrides the static env: for later steps.

Related guides

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