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

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

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Reactions: 85
  • Comments: 37

Commits related to this issue

Most upvoted comments

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

+1. Get this fixed github, cmon.

I’m having the same issue

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

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

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

just use vars instead of env

Still doesn’t work. It’s weird.

2023 and still have the same issue

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

@chrisk8er do u mean instead of ${{ env.SOMETHING }}, use ${{ var.SOMETHING }}? (this isn’t working) can u give an eg?

Yes…

${{ vars.SOMETHING }}

you forgot to put the s

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.

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

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