Three layers of env
Environment variables in workflows can come from three layers, with predictable precedence:
- Step env — defined under a step's
env:. Highest priority for that step. - Job env — defined under a job's
env:. Visible to all steps in that job. - Workflow env — defined at the top level. Visible everywhere.
If two layers define the same name, the more specific layer wins (step > job > workflow).
Reading env from expressions
Two access methods, with a subtle difference:
- Inside a shell run:
$VAR(bash) — uses the actual process environment at execution time. - In an expression:
${{ env.VAR }}— read at parse time, before the step runs. Some context is not yet available; see below.
Context precedence in the GITHUB_ENV file
Steps can write to $GITHUB_ENV to add an env var that's visible in subsequent steps. This is how you compute a value in step 2 and use it in step 5.