GitHub Actions "Unrecognized named-value: 'env'" in CI
Each workflow location exposes only certain contexts. Referencing env (or another context) in a place that does not provide it makes the expression compiler reject the file with "Unrecognized named-value".
What this error means
The run fails with "Invalid workflow file" and "(Line: N, Col: M): Unrecognized named-value: 'env'. Located at position 1 within expression: env.X".
Invalid workflow file: .github/workflows/ci.yml
(Line: 12, Col: 14): Unrecognized named-value: 'env'.
Located at position 1 within expression: env.DEPLOYCommon causes
env referenced where it is not in scope
The env context is not available in runs-on, in some job-level keys, or in concurrency evaluated before the job environment exists.
A typo treated as a context name
A misspelled context or a bare word inside ${{ }} is parsed as a named-value the compiler does not recognize.
How to fix it
Use a context that is available there
- Check the contexts allowed at that key in the GitHub docs.
- Replace
envwithvars,github, or a value passed in another way. - Re-run the workflow.
# instead of env in runs-on, use a matrix or vars
runs-on: ${{ matrix.os }}Move the logic to a step where env exists
Read env inside a run step or a step-level if, where the env context is populated.
How to prevent it
- Consult the context availability table before using a context.
- Prefer
vars/secretsfor values needed at evaluation-sensitive keys. - Validate expressions in a schema-aware editor.