Skip to content

"Unrecognized named-value: 'env'. Located at position 1 within expression" when used in reusable workflow jobs #2372

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

Open
nive-copia opened this issue Jan 16, 2023 · 83 comments
Assignees
Labels
bug Something isn't working

Comments

@nive-copia
Copy link

Describe the bug
Usage of env in workflow that uses reusable workflow generates "Unrecognized named-value: 'env'. Located at position 1 within expression"

To Reproduce
Use the following yml:

name: Test Workflow

on:
  push:

env:
  SOMETHING: 1000

  test:
    name: call workflow
    uses: ./.github/workflows/callee.yml
    secrets: inherit
    with:
      run_url: "{run_url}"
      message: ${{ env.SOMETHING }}

Expected behavior
env.SOMETHING is usable and can be passed into reusable workflow

Actual behavior

The workflow is not valid. .github/workflows/create-branch.yml (Line: #, Col: ##): Unrecognized named-value: 'env'. Located at position 1 within expression: env.SOMETHING

Runner Version and Platform

Version of your runner?

OS of the machine running the runner?
ubuntu-latest

What's not working?

image

@nive-copia nive-copia added the bug Something isn't working label Jan 16, 2023
@GrayJack
Copy link

I'm having the same issue

@nicole0707
Copy link

I have the same issue, there is workaround to use $GITHUB_OUTPUT instead.

@rajrupdasofficial
Copy link

Having the same issue . When it's going to fix?
any work around of it?

@nive-copia
Copy link
Author

Hi GHA folks: Any update on providing this capability? Some of us are using workarounds, including the one suggested by @nicole0707. But, having this feature will make the intent very clear and clean.

@ghost
Copy link

ghost commented Jan 26, 2023

hello! if i can help u. or something need to do.say step b step

@lucasmellos
Copy link

workaround is to use as a secret in the main workflows and then you'll be able to parse it to env in the reusable workflow like

env:
   SECRET: ${{secrets.MY_SECRET}}

@hoancs
Copy link

hoancs commented Feb 17, 2023

I'm having the same issue. Have we got any update?

@srinadhbh
Copy link

workaround is to use as a secret in the main workflows and then you'll be able to parse it to env in the reusable workflow like

env:
   SECRET: ${{secrets.MY_SECRET}}

In my case, git is considering subscription id as a secret. I am trying to print NSG/ASG id and git is omitting the output.

@hurricup
Copy link

hurricup commented Mar 5, 2023

Trying to use this approach to workaround #520 and bummer...

hurricup added a commit to Camelcade/Perl5-IDEA that referenced this issue Mar 5, 2023
- use public qodana linter for PRs
- do not collect and analyze coverage

Coverage analysis suppressed in the _coverage.yml instead of main workflow because of the bug on actions side, see  actions/runner#2372
@hurricup
Copy link

hurricup commented Mar 5, 2023

It is also unavailable in called workflow. I tried to move check into there and got:

b5676355294c9b6943a4a68c5 (Line: 14, Col: 9): Unrecognized named-value: 'env'. Located at position 1 within expression: env.COVERALLS_REPO_TOKEN Camelcade/Perl5-IDEA/.github/workflows/_coverage.yml@d08cee137234bd0b5676355294c9b6943a4a68c5 (Line: 14, Col: 9): Unexpected symbol: '${{'. Located at position 1 within expression: ${{ env.COVERALLS_REPO_TOKEN }}
    secrets: inherit

Called workflow is:

# re-usable workflow to merge and process coverage
name: Coverage

on:
  workflow_call:

env:
  COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}

jobs:
  analyze:
    name: Analysis
    runs-on: ubuntu-latest
    if: ${{ env.COVERALLS_REPO_TOKEN }}
....

hurricup added a commit to Camelcade/Perl5-IDEA that referenced this issue Mar 5, 2023
- use public qodana linter for PRs
- do not collect and analyze coverage

Coverage analysis suppressed in the _coverage.yml instead of main workflow because of the bug on actions side, see  actions/runner#2372
hurricup added a commit to Camelcade/Perl5-IDEA that referenced this issue Mar 5, 2023
- use public qodana linter for PRs
- do not collect and analyze coverage

Coverage analysis suppressed in the _coverage.yml instead of main workflow because of the bug on actions side, see  actions/runner#2372
@carrill1
Copy link

carrill1 commented Apr 4, 2023

I'm having the same issue 😐

@iBasit
Copy link

iBasit commented Apr 6, 2023

+1

@alexl-shopware
Copy link

+1. Get this fixed github, cmon.

@whsalazar
Copy link

The env context is not available from jobs.<job_id>.with.<with_id>. See https://docs.github.com/en/enterprise-cloud@latest/actions/learn-github-actions/contexts#context-availability

@hurricup
Copy link

@whsalazar the question is what the reason behind this? And if there is no real reason, would be nice to have it.

@harrisrobin
Copy link

I guess I wasted 30 mins of my life and ended up here like the rest of us

@whsalazar
Copy link

You can't use the env context outside steps, as described in the docs:

You can use the env context in the value of any key in a step except for the id and uses keys. Feel free to submit feedback and feature request at https://github.com/orgs/community/discussions/categories/actions?discussions_q=is%3Aopen+env+jobs+category%3AActions

@guanyingjie
Copy link

I have the same issue, hope github action can pass the env variable in the furture

@rijnhard
Copy link

Nasty workaround: https://stackoverflow.com/a/74217028/834280

@kschaer
Copy link

kschaer commented Jun 13, 2023

Same problem here. I have several reusable workflows that should receive the same with inputs - it's a shame I cannot simply set up the environment variables in the parent (caller) workflow and pass to the reusable (child) workflows.

@miguelangelgil
Copy link

miguelangelgil commented Jun 14, 2023

The solution is to pass the environment variables as the output of a job:

name: Test Workflow

on:
  push:

env:
  SOMETHING: 1000

jobs:
 get-env-vars:
    name: Get Environment vars
    runs-on: some-runner
    outputs:
      SOMETHING: ${{ env.SOMETHING }}
    steps:
      - run: echo "null"

  test:
    name: call workflow
    needs: [get-env-vars]
    if: ${{ always() }}
    uses: ./.github/workflows/callee.yml
    secrets: inherit
    with:
      run_url: "{run_url}"
      message: ${{  needs.get-env.outputs.SOMETHING }}

@ffineis
Copy link

ffineis commented Jun 15, 2023

Hey this got me really close - at least now i can reference names of env vars I need in with, but this approach won't work if the original env variable is a secret since GH doesn't export outputs that are secrets.

Warning: Skip output 'MY_SECRET' since it may contain secret.

@miguelangelgil
Copy link

@ffineis To pass secrets use secrets instead with. In the above case i use secrets: inherit that take the secrets that you define in yours reusable workflow if they are accessible from the current workflow.

@ffineis
Copy link

ffineis commented Jun 16, 2023

@miguelangelgil yes thanks secrets: inherit was the trick to expose secrets in the reusable workflow - thx! Wish I had seen this after 3 hours of smashing head in.

@joshjohanning
Copy link

You can use ${{ vars.MY_VAR }} stored in the repository instead of env when referencing in reusable workflows. Not perfect, but it works

@sajati
Copy link

sajati commented Jul 21, 2023

2023 and still have the same issue

@anajuliabit
Copy link

please github devs do something 😩

@ulidtko
Copy link

ulidtko commented Sep 4, 2024

@anajuliabit I'm mostly sure that exactly 0 of GH devs are subscribed to every issue and are reading every comment. You'd have to summon their attention via explicit pings.

For example, ping @ericsciple @TingluoHuang

@ericsciple
Copy link
Collaborator

ericsciple commented Sep 4, 2024

@ericsciple
Copy link
Collaborator

ericsciple commented Sep 4, 2024

To elaborate a bit more, env is for process environment variables. Also, secrets can be mapped into env, so if secrets isn't allowed, then env isn't allowed either.

Similarly, the secrets context is generally only allowed within a job. It is not allowed within fields that are used by our server to manage the workflow orchestration.

@ericsciple ericsciple self-assigned this Sep 4, 2024
@ericsciple
Copy link
Collaborator

ericsciple commented Sep 4, 2024

Skimming the replies regarding use cases...

One solution might be to check-in a script which sets up your job environment variables. https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions#setting-an-environment-variable. For scenarios involving run-context or workflow dispatch inputs, $GITHUB_EVENT_PATH might also help.

Not perfect, but might work for many scenarios.

@ericsciple
Copy link
Collaborator

Also note, reusable workflows are sort of a security boundary. That is why env values don't flow to reusable workflows. Otherwise callers could influence the jobs in ways unintended by the reusable workflow author. E.g. consider https://github.blog/changelog/2022-03-21-github-actions-restrict-self-hosted-runner-groups-to-specific-workflows/

@ulidtko
Copy link

ulidtko commented Sep 5, 2024

Hi @ericsciple thanks for responding 🙏

I know it's tough to unbundle the assortment of various issues that are being conflated into one. Perhaps you can think of error message improvements that'd send people to corresponding docs explaining that certain usage isn't supported, neither will be? That'd be super helpful to reduce confusion, as apparently there's a lot of difficulty in locating the authoritative docs.

For example, I'm coming from a (prematurely closed) issue #1189 which reports the same error — but without reusable workflows, secrets, and under jobs.<job_id>.env (not in jobs.<job_id>.with.<with_id>).

I.e. this does not work, throws the error:

jobs:
  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

#-- NOTE: the workflow author wants both values as env-vars, to be used in shell steps.
#-- NOTE: the second var is defined using the first var ${{ env.version }}

# ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
# The workflow is not valid. .github/workflows/release.yml (Line: 190, Col: 21):
# Unrecognized named-value: 'env'. Located at position 1 within expression: env.version

Can this be helped with somehow?

@ericsciple
Copy link
Collaborator

+1 thanks @ulidtko - good feedback. I will forward along internally.

dentarg added a commit to Starkast/wikimum that referenced this issue Oct 20, 2024
jan-molak added a commit to serenity-js/serenity-js that referenced this issue Nov 3, 2024
@bnhmn
Copy link

bnhmn commented Nov 13, 2024

This didn't work back in late 2021 when reusable workflows were introduced and it still doesn't work three years later in 2024. See you in 3 years.

@KornevNikita
Copy link

Another +1. Hopefully by the 1001st comment we'll get this working.

@ulidtko
Copy link

ulidtko commented Dec 20, 2024

Ping @ericsciple, any update you could give publically?..

@ab-smith
Copy link

ab-smith commented Dec 27, 2024

Another +1 indeed; I understand that env is probably not ideal but we should have a proper alternative pattern in this case for reusability.

@esaporski
Copy link

Soon we can wish this issue a Happy Birthday! 🎂

@Armadillidiid
Copy link

It seems like I'm early to the party. Just encountered this issue

@magusd
Copy link

magusd commented Jan 21, 2025

well, looks like it's hopeless waiting for a solution, will try one of the workarounds

surn-nykredit-dk added a commit to Nykredit/.github that referenced this issue Jan 24, 2025
@roeezolantz
Copy link

Any chance? 😢

@hugtalbot
Copy link

Wow, we just faced this issue and discovered it's a real issue, not yet solved 😲
Any solution would be appreciated

@dyahnov
Copy link

dyahnov commented Apr 3, 2025

Same here today, wtf?

@munyaradzi-hobbstech
Copy link

This needs to be fixed guys

@hantastic3
Copy link

This needs to be fixed

@esaporski
Copy link

Forget about it guys, GitHub Actions is abandonware.

@rik-howard
Copy link

Please fix this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests