-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unrecognized named-value: 'env'. for job conditional #1189
Comments
Base on https://docs.github.com/en/actions/reference/context-and-expression-syntax-for-github-actions#context-availability You can create feature request at https://github.community/c/code-to-cloud/github-actions/41 |
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 |
I think it's suppose to work but doesn't. There is an an official example of using env in an if here: |
No, in that case the |
I see. Your explanation cleared that up for me. Thanks! You're right, the official error message is no help. |
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 |
@framerate While it is annoying and, in my opinion, the docs are not very clear, I do not see any outright errors in these docs. They make it clear that you can always use environment variables at the lowest level (commands being executed on the "runner") and hint that "different points in the workflow" have access to different things. Perhaps one thing they could do to make it better would be to explain that when they say "GitHub Actions" they are apparently talking a specific component of the system, e.g. (emphasis added)
|
Right. That part is okay but the line:
I believe is completely wrong, isnt it? Or at least out of place since an env variables CANNOT be used in a job, even if an "if" can. So why say "job" here at all? It just makes people think we can use an env variables since that's the section we're reading. Removing the words "job or" from that line would probably have removed my confusion at least. |
Maybe this is an English language "nit", but I think by using "which" instead of "that" it gives the wrong impression (i.e. explaining what an if statement might do rather than clarifying that we're talking about a specific if statement that does a particular thing: determining whether or not something gets sent to the runner, which means it is happening on "GitHub Actions" not on "the runner" and thus needs to read it from the env context. |
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 :/ |
apparently env variable is not available inside `if` jobs LOL actions/runner#1189 (comment)
…viewer pr_reviewer env is not accessible in jobs.if actions/runner#1189
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. |
Also got this error when trying to define job-level acme-bundle:
runs-on: ubuntu-20.04
needs: build
env:
# if triggered from a branch containing /, use "wip", otherwise tag name
version: ${{ contains(github.ref_name, '/') && 'wip' || github.ref_name }}
fullfilename: acme-${{ env.version }}.${{ github.sha }}.bundle
steps:
...
- name: Pack
run: tar -czf $fullfilename --format posix -C DIST .
- name: Upload
run: aws s3 cp $fullfilename s3://$BUCKET/ACME/$version/$fullfilename — by GH Actions rules, the definition of
Instead of trying to untangle the truckload of flavors of "a variable" 🙄 from GH Actions docs ( Shell variables (and "actions" BTW too) are simple enough: acme-bundle:
runs-on: ubuntu-20.04
needs: build
# NOTE the job-level `env` yaml is useless https://github.com/actions/runner/issues/1189
steps:
- name: Format acme-bundle filename
run: |
# if triggered from a branch containing /, use "wip", otherwise tag name
version="${{ contains(github.ref_name, '/') && 'wip' || github.ref_name }}"
fullfilename="acme-${version}.${GITHUB_SHA}.bundle"
{ echo "version=$version"
echo "fullfilename=$fullfilename"
} >> $GITHUB_ENV
...
- name: Pack
run: tar -czf $fullfilename --format posix -C DIST .
- name: Upload
run: aws s3 cp $fullfilename s3://$BUCKET/ACME/$version/$fullfilename |
I've lost count how many times I've stumbled on this limitation and spun my wheels. See actions/runner#1189
env:
MY_ENV: test
jobs:
some-job:
uses: Org/repo/path/to/workflow.yml@master
with:
some-input: ${{ env.MY_ENV }} |
env cannot be used within a with block (actions/runner#1189 (comment))
I just got bit by this, not with |
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 |
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 With that idea in mind the abomination was created: env:
# Global vars
YOUR_VAR_1: 'whatever value you want to pass'
YOUR_VAR_2: rc.${{ github.sha }}-whatever
jobs:
github_sucks:
runs-on: ubuntu-latest
outputs:
YOUR_VAR_1: ${{ steps.blah.outputs.YOUR_VAR_1 }}
YOUR_VAR_2: ${{ steps.blah.outputs.YOUR_VAR_2 }}
steps:
- id: blah
run: |
vars="
YOUR_VAR_1
YOUR_VAR_2
"
setOutput() {
echo "${1}=${!1}" >> "${GITHUB_OUTPUT}"
}
for name in $vars; do
setOutput $name
done
build:
needs: [ <actual dependencies> , github_sucks ]
uses: ./.github/workflows/build_action.yml
secrets: inherit
with:
whatever_input_1: ${{ needs.github_sucks.outputs.YOUR_VAR_1 }}
whatever_input_2: ${{ needs.github_sucks.outputs.YOUR_VAR_2 }}
The big downside, beside this being a very big crutch, is that you have to hardcode the variable names in the converter job. |
## Description Looks like we can not use a env variable for setting the "environment" property because the value is evaluated by GitHub action before the "STAGE" variable is set. See actions/runner#1189
For anyone that ended up here because it's the first result on google and you're having issues with using |
* - Fixed oversight where the source branch name on a pull request event was incorrectly defined as `github.ref_name` when it should have been `github.head_ref`. - Removed concurrency limit from tests and prototype builds, since there is no issue with running multiple tests on different machines at the same time; they won't affect each other. The only workflow that must use a mutex is deployment. * Attempt at fixing the skip expression. I'm not actually sure what type `steps.artifact.outputs.exists` is but it *might* actually be string and not a boolean based on the definition: https://github.com/softwareforgood/check-artifact-v4-existence/blob/e275f50d133e31f81aa1088033a787639e4d5a53/action.yml#L35-L40 This open issue also suggests that indeed, booleans are not actually booleans and are just strings of truthy phrases: actions/runner#2238 Since the issue above was opened in late 2022, it's probably not going to be fixed any time soon. * Turns out `env` context isn't available in `job.if`, WTF!? actions/runner#1189 (comment)
I can't believe that three years later, and with so many complaints, github has not fixed this yet. |
Closed, but not fixed. |
On master this works: - name: Create GH Release uses: softprops/action-gh-release@v2 with: generate_release_notes: true files: | dist/*.tar.gz prerelease: ${{ env.IS_PRERELEASE }} env: GITHUB_TOKEN: ${{ secrets.PULUMI_BOT_TOKEN }} On release-3.x.x this fails: publish: name: publish needs: - prerequisites - test-nodejs - test-python - test-dotnet - test-go uses: ./.github/workflows/publish.yml secrets: inherit with: version: ${{ needs.prerequisites.outputs.version }} isPrerelease: ${{ env.IS_PRERELEASE }} ``` Invalid workflow file: .github/workflows/release.yml#L194 The workflow is not valid. .github/workflows/release.yml (ine: 194, Col: 21): Unrecognized named-value: 'env'. Located at position 1 within expression: env.IS_PRERELEASE ``` Possibly related actions/runner#1189 Working around by in-lining the ENV var.
On master this works: - name: Create GH Release uses: softprops/action-gh-release@v2 with: generate_release_notes: true files: | dist/*.tar.gz prerelease: ${{ env.IS_PRERELEASE }} env: GITHUB_TOKEN: ${{ secrets.PULUMI_BOT_TOKEN }} On release-3.x.x this fails: ``` publish: name: publish needs: - prerequisites - test-nodejs - test-python - test-dotnet - test-go uses: ./.github/workflows/publish.yml secrets: inherit with: version: ${{ needs.prerequisites.outputs.version }} isPrerelease: ${{ env.IS_PRERELEASE }} ``` With: ``` Invalid workflow file: .github/workflows/release.yml#L194 The workflow is not valid. .github/workflows/release.yml (ine: 194, Col: 21): Unrecognized named-value: 'env'. Located at position 1 within expression: env.IS_PRERELEASE ``` Possibly related actions/runner#1189 Working around by in-lining the ENV var.
Guys, it's not github anymore, it's microsoft and we relive the same nightmare here what was before called Azure DevOps... |
On master this works: - name: Create GH Release uses: softprops/action-gh-release@v2 with: generate_release_notes: true files: | dist/*.tar.gz prerelease: ${{ env.IS_PRERELEASE }} env: GITHUB_TOKEN: ${{ secrets.PULUMI_BOT_TOKEN }} On release-3.x.x this fails: ``` publish: name: publish needs: - prerequisites - test-nodejs - test-python - test-dotnet - test-go uses: ./.github/workflows/publish.yml secrets: inherit with: version: ${{ needs.prerequisites.outputs.version }} isPrerelease: ${{ env.IS_PRERELEASE }} ``` With: ``` Invalid workflow file: .github/workflows/release.yml#L194 The workflow is not valid. .github/workflows/release.yml (ine: 194, Col: 21): Unrecognized named-value: 'env'. Located at position 1 within expression: env.IS_PRERELEASE ``` Possibly related actions/runner#1189 Working around by in-lining the ENV var.
On master this works: - name: Create GH Release uses: softprops/action-gh-release@v2 with: generate_release_notes: true files: | dist/*.tar.gz prerelease: ${{ env.IS_PRERELEASE }} env: GITHUB_TOKEN: ${{ secrets.PULUMI_BOT_TOKEN }} On release-3.x.x this fails: ``` publish: name: publish needs: - prerequisites - test-nodejs - test-python - test-dotnet - test-go uses: ./.github/workflows/publish.yml secrets: inherit with: version: ${{ needs.prerequisites.outputs.version }} isPrerelease: ${{ env.IS_PRERELEASE }} ``` With: ``` Invalid workflow file: .github/workflows/release.yml#L194 The workflow is not valid. .github/workflows/release.yml (ine: 194, Col: 21): Unrecognized named-value: 'env'. Located at position 1 within expression: env.IS_PRERELEASE ``` Possibly related actions/runner#1189 Working around by in-lining the ENV var.
Another longstanding gotcha. People are disappointed. - actions/runner#1189 - actions/runner#2372
Describe the bug
Use of
env
in job conditionals causes an invalid config. Cross posting this from nektos/act#720Expected behaviour
GitHub Actions should not error regarding
${{ !env.ACT }}
Actual behaviour
GitHub Actions says workflow is not valid because of
${{ !env.ACT }}
Workflow and/or repository
Erroring Workflow
workflow
The text was updated successfully, but these errors were encountered: