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 abovejobs:. - Reference
$NAMEor${{ 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 referencesecrets; pass those via stepenv:instead. - A value written to
$GITHUB_ENVat runtime overrides the staticenv:for later steps.
Related guides
How to Set Permissions for the GITHUB_TOKEN in GitHub ActionsRestrict or grant scopes for the automatic GITHUB_TOKEN in GitHub Actions with the permissions key, following…
How to Safely Use a Context Value in a run Step in GitHub ActionsAvoid script injection in GitHub Actions by passing untrusted context values like PR titles into a run step t…