runner icon indicating copy to clipboard operation
runner copied to clipboard

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

Open nive-copia opened this issue 2 years ago • 69 comments

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 avatar Jan 16 '23 01:01 nive-copia

I'm having the same issue

GrayJack avatar Jan 19 '23 16:01 GrayJack

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

nicole0707 avatar Jan 23 '23 06:01 nicole0707

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

rajrupdasofficial avatar Jan 24 '23 11:01 rajrupdasofficial

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.

nive-copia avatar Jan 26 '23 23:01 nive-copia

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

ghost avatar Jan 26 '23 23:01 ghost

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}}

lucasmellos avatar Feb 14 '23 23:02 lucasmellos

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

hoancs avatar Feb 17 '23 02:02 hoancs

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.

srinadhbh avatar Feb 17 '23 22:02 srinadhbh

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

hurricup avatar Mar 05 '23 08:03 hurricup

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 avatar Mar 05 '23 08:03 hurricup

I'm having the same issue 😐

carrill1 avatar Apr 04 '23 00:04 carrill1

+1

iBasit avatar Apr 06 '23 21:04 iBasit

+1. Get this fixed github, cmon.

alexl-shopware avatar Apr 18 '23 20:04 alexl-shopware

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

whsalazar avatar Apr 20 '23 20:04 whsalazar

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

hurricup avatar Apr 21 '23 03:04 hurricup

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

harrisrobin avatar Apr 21 '23 19:04 harrisrobin

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

whsalazar avatar Apr 22 '23 06:04 whsalazar

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

guanyingjie avatar May 05 '23 09:05 guanyingjie

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

rijnhard avatar May 14 '23 09:05 rijnhard

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.

kschaer avatar Jun 13 '23 17:06 kschaer

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 }}

miguelangelgil avatar Jun 14 '23 14:06 miguelangelgil

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.

ffineis avatar Jun 15 '23 23:06 ffineis

@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.

miguelangelgil avatar Jun 16 '23 06:06 miguelangelgil

@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.

ffineis avatar Jun 16 '23 13:06 ffineis

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

joshjohanning avatar Jul 03 '23 15:07 joshjohanning

2023 and still have the same issue

sajati avatar Jul 21 '23 04:07 sajati

Still doesn't work. It's weird.

SerGeRybakov avatar Aug 18 '23 10:08 SerGeRybakov

Still doesn't work. It's weird.

Post a sample of what is not working.

whsalazar avatar Aug 18 '23 16:08 whsalazar

+1 same issue

cvetinovic avatar Oct 19 '23 11:10 cvetinovic

+1, same thing here.

rmogio-encora avatar Nov 10 '23 15:11 rmogio-encora