question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Workflow level `env` does not work properly in all fields.

See original GitHub issue

Describe the bug When using workflow level environment variables they do not work when I use them to substitute for jobs.build.name or jobs.build.runs-on. See workflow file below for example:

name: Testing workflow leve env vars
on:
  push:
    branches:
      - develop

env:
  aws_account: cfaittoolsnp
  environment: dev

jobs:
  build:
    name: Deploy|${{ env.aws_account }}
    runs-on: ${{ env.aws_account }}
    steps:
    - name: Checkout
      uses: actions/checkout@v2
    - name: Init
      run: |
        echo ${{ env.aws_account }}

To Reproduce Steps to reproduce the behavior: 1.- Run the workflow file above to receive the following error: The workflow is not valid. .github/workflows/dev.yml (Line: 15, Col: 11): Unrecognized named-value: 'env'. Located at position 1 within expression: env.aws_account,.github/workflows/dev.yml (Line: 16, Col: 14): Unrecognized named-value: 'env'. Located at position 1 within expression: env.aws_account

Expected behavior The expected behavior is that using the workflow file above the build.name would be Deploy|cfaittoolsnp and the build.runs-on would be cfaittoolsnp.

Runner Version and Platform

Running latest version of linux self-hosted runner.

OS of the machine running the runner? linux (ubuntu 18.04)

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:255
  • Comments:45

github_iconTop GitHub Comments

61reactions
tjcorrcommented, Jan 25, 2022

This is also an issue with reusable workflow. For example:

env:
  DOTNET_VERSION: 5.0.x    

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  call-workflow-passing-data:
      uses: ....reusable.yml@main
      with:
          dotnetversion: ${{ env.DOTNET_VERSION }}`

Does not work.

34reactions
xor-freenetcommented, Mar 14, 2022

@restjohn wrote:

The concept to realize, I think, is that the intent of environment variables is for them to be available in the context that a job step is executing, not in the context of DEFINING a job, which is basically the context of the GitHub Actions platform itself. […] Now, there might be potential for a less cumbersome solution than having to use outputs and needs references, such as user-defined variables and functions that can augment the job definition context, but env is certainly not the correct place for that.

Thanks for your input 😃

It may be true that that is how the implementation is implemented and intended currently (or not true, who knows?)

But: The sole purpose of an implementation of software is to serve the users needs, it has no purpose of its own.

Therefore, if it cannot serve the needs of the users, it has to change.

It should not be the other way around, the users should not be asked to change their needs to follow the needs of the implementation 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use env variable on workflow level github-actions
Regarding the use of environment variables at different levels inside the workflow, here is an example with WORKFLOW, JOB and STEP variables ...
Read more >
How to Manage GitHub Actions Environment Variables and ...
In this tutorial, you will learn different ways to save your GitHub Actions environment variables and secrets you can use when required while ......
Read more >
Workflow validator not working as expected
Environment field is configured correctly in field configuration. Environment is required. But it is not present on screen. Answer.
Read more >
Environment Variables - Bitrise Docs
An Environment Variable (Env Var) is a key-value pair that holds data that you can use in your builds by inserting them into...
Read more >
Runtime Variables in GitHub Actions
Here, we set an environment variable for the step: Any code or action that the step calls will now have the environment variable...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found