runner: Unrecognized named-value: 'env'. for job conditional
Describe the bug
Use of env
in job conditionals causes an invalid config. Cross posting this from nektos/act#720
Expected behaviour
GitHub Actions should not error regarding ${{ !env.ACT }}
Actual behaviour
GitHub Actions says workflow is not valid because of ${{ !env.ACT }}
The workflow is not valid. .github/workflows/deploy.yml (Line: 11, Col: 13): Unrecognized named-value: 'env'. Located at position 2 within expression: !env.ACT
Workflow and/or repository
workflow
name: Deploy
on:
push:
branches:
- release
# run for every pull request
pull_request: {}
jobs:
deploy:
name: Deploy
if: ${{ !env.ACT }} # skip during local actions testing
runs-on: ubuntu-latest
strategy:
matrix:
node: [12]
steps:
- name: Checkout repo
uses: actions/checkout@v2
- name: Setup node
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}
- name: đĽ Download deps
uses: bahmutov/npm-install@v1
with:
useLockFile: false
- name: Deploy
run: npx semantic-release@15
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 42
- Comments: 16 (1 by maintainers)
Commits related to this issue
- Fix env thing apparently env variable is not available inside `if` jobs LOL https://github.com/actions/runner/issues/1189#issuecomment-880110759 — committed to joshuanianji/idris-2-docker by joshuanianji 2 years ago
- fix(github-actions): move if conditional to step instead job in pr_reviewer pr_reviewer env is not accessible in jobs.if https://github.com/actions/runner/issues/1189 — committed to vincejv/fpi-framework by vincejv 2 years ago
- https://github.com/actions/runner/issues/1189 — committed to saltchess/arcaea-wiki-sometry by deleted user 2 years ago
- Move 'if' from step to job See https://github.com/actions/runner/issues/1189 — committed to AntaresSimulatorTeam/Antares_Simulator by flomnes 2 years ago
- ci: env variables do not work outside of steps, github docs seem to be wrong https://github.com/actions/runner/issues/1189 — committed to Radialarray/codelibrary by Radialarray a year ago
- jobs.<job>.if doesn't have access to env context I've lost count how many times I've stumbled on this limitation and spun my wheels. See https://github.com/actions/runner/issues/1189 — committed to tetsuo13/AspNetCore.DataProtection.MySql by tetsuo13 10 months ago
- Prospective fix for failing nightly CI job env cannot be used within a with block (https://github.com/actions/runner/issues/1189#issuecomment-1741672276) — committed to slint-ui/slint by tronical 8 months ago
Base on https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#context-availability
env
context is not available tojob.if
You can create feature request at https://github.community/c/code-to-cloud/github-actions/41
Well I wasted a few dollars of minutes and a few hours of my day based on that sentence so whether or not everyone gets confused by it I can say with certainty I got confused and frustrated by it.
Whether or not anyone wants to fix it is beyond the scope of my authority but enough of these frustrations in the documentation and Iâll surely go back to circleci for my CI đ
env
is also not usable within a job whichuses
a shared workflow, within thewith
block e.g.:Would really like this functionality to be in place - I donât understand how itâs possible to develop any sort of custom caching without this functionality. This would save us a tremendous amount of time and sanity.
I think itâs suppose to work but doesnât. There is an an official example of using env in an if here: https://docs.github.com/en/actions/learn-github-actions/environment-variables#using-contexts-to-access-environment-variable-values
Following up to this: I still think the docs are wrong. They state:
This seems to imply that an env variable could be used in a
job
and astep
but that doesnât seem to be the case.Did anyone create that feature request? I appreciate the link to contexts docs because this behavior was not at all obvious to me from this documentation:
So I guess they are using the term
step
to have some technically precise meaning, like a subkey ofjobs.<job_id>.steps
? Seems like the validator could give much better hints about the cause of the error here (e.g. âYou attempted to usedenv
, butenv
is not available in the context of ⌠See this docs page for more detailsâŚâNo, in that case the
if
is part of astep
, which works (seejobs.<job_id>.steps.if
in table linked below). The problem is that it is counter-intuitive for a developer who may be in the habit of thinking about the YAML file as something like a âshell scriptâ wherein environment variables are globally accessible. The things that can be accessed (context) in a given place (workflow key) are listed here: https://docs.github.com/en/actions/learn-github-actions/contexts#context-availability I think it would be very helpful if attempted accesses to unavailable contexts caused a warning to be generated (and perhaps linked to that table).Well, to a poor soul that stumbles upon this issue, I have a solution (crutch-lution?) for the crutch-full github actions system.
The idea is to convert
env:
tooutputs
and they for whatever unholy reason đŻ can be used in thewith
for workflow call.With that idea in mind the abomination was created:
The big downside, beside this being a very big crutch, is that you have to hardcode the variable names in the converter job. I did not found a sane way to even get the list of
env
keys, you could use${{ toJSON(env) }}
and parse it in therun
viajq
or something similar but it would be adding more salt to the wound.I just got bit by this, not with
env
, but withvars
. And yes, it appears to be an odd edgecase of failed support in reusable workflows around passing inputs to actions. We have an organization level variable ofNODE_VERSION
that we cannot use in any of our workflows. It produces the errorUnrecognized named-value: 'vars'. Located at position 1 within expression: vars.NODE_VERSION
Oh what theâŚwhy github actions have to be so much worse and immature compared to the gitlab.
Now I have to rewrite everything again, great idea of using
env:
for global constants goes to the dumpster.Also got this error when trying to define job-level
env
-vars in terms of other job-levelenv
-vars:â by GH Actions rules, the definition of
env.fullfilename
is forbidden to useenv.version
on the previous line đ¤Śââď¸Instead of trying to untangle the truckload of flavors of âa variableâ đ from GH Actions docs (
vars
definable on 5 nesting levels,env
vars with 3 nesting levels, contexts⌠oh my!) â just use the shell.Shell variables (and âactionsâ BTW too) are simple enough: