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. is unrecognised on job level's 'if'-expression when calling reusable workflow

See original GitHub issue

the idea is to have a workflow_dispatch input to choose wether or not to execute tests after the build part is done.

Describe the bug environment variable defined on workflow level is not available for if-condition on job level - in case the job is calling another “reusable” workflow. everything is fine within a regular job and it’s steps.

To Reproduce Example:

name: ay_test_condition

on:
  workflow_dispatch:
    inputs:
      build_skip:
        description: 'skip maven and chart builder'
        required: true
        default: false
        type: boolean  
      test_skip:
        description: 'skip product integration tests'
        required: true
        default: false
        type: boolean    

# workflow level env
env:
  BUILD_SKIP: ${{ github.event.inputs.build_skip == 'true' }}
  TEST_SKIP: ${{ github.event.inputs.test_skip == 'true' }} 

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - name: Display build environment
        id: displayBuildEnv
        shell: bash
        run: |
          echo "build_skip: ${{ github.event.inputs.build_skip }}";
          echo "env.BUILD_SKIP: ${{ env.BUILD_SKIP }}";
          echo "test_skip : ${{ github.event.inputs.test_skip }}";
          echo "env.TEST_SKIP: ${{ env.TEST_SKIP }}";
      
      - name: build something
# works fine here (at workflow.job.step level)      
        if: ${{ env.BUILD_SKIP == 'false' }}
        run: |
          echo "Building something"   

  test:
    needs: build
# does not work here (at workflow.job-workflow_caller)    
    if: ${{ env.TEST_SKIP == 'false' }}
    uses: ./.github/workflows/ay_test-workflow2.yml
    with:
      teststatus: true   

Expected behavior the env should be available everywhere, since it’s declared on workflow level.

Runner Version and Platform

Current runner version: ‘2.287.1’ Operating System Ubuntu 20.04.3 LTS Virtual Environment Environment: ubuntu-20.04 Version: 20220131.1 Virtual Environment Provisioner 1.0.0.0-main-20220201-1

What’s not working?

Errormessage:

The workflow is not valid. .github/workflows/ay_test_condition.yml (Line: 45, Col: 9): Unrecognized named-value: 'env'. Located at position 1 within expression: env.TEST_SKIP == 'false'

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:9
  • Comments:21 (5 by maintainers)

github_iconTop GitHub Comments

7reactions
leighmccullochcommented, Dec 1, 2022

I’m seeing the same problem with env at the workflow level and reusable workflows.

For example, this does not work:

name: Rust

on:
  push:
    branches: [main]
  pull_request:

env:
  CARGO_HACK_ARGS: --feature-powerset --exclude-features default --group-features base64,serde,arbitrary,hex

jobs:
  publish-dry-run:
    if: startsWith(github.head_ref, 'release/')
    strategy:
      matrix:
        sys:
        - os: ubuntu-latest
          target: wasm32-unknown-unknown
        - os: ubuntu-latest
          target: x86_64-unknown-linux-gnu
    uses: stellar/actions/.github/workflows/rust-publish-dry-run.yml@main
    with:
      runs-on: ${{ matrix.sys.os }}
      target: ${{ matrix.sys.target }}
      cargo-hack-feature-options: ${{ env.CARGO_HACK_ARGS }} # 👈 Does not work
6reactions
1k-offcommented, Feb 26, 2023

Hey!

Using env variables in reusable workflows still unavailable. Using like this (see code below) still throws an error.

env:
  FOO: bar
  

jobs:
  build:
    name: Build
    uses: user/repo/.github/workflows/workflow.yml@main
    with:
      some-input: ${{ env.FOO}}

Is there any plans or deadlines to fix this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Environment variable not recognized when used for ...
The solution is to pass the environment variables as the output of a job, like here.
Read more >
Reusable workflows in Github Actions - YouTube
Source code: https://github.com/HoussemDellai/github-actions-course Follow me on Twitter for more content: ...
Read more >
Avoid Duplication! GitHub Actions Reusable Workflows
If Composite Actions can be thought of as Templates, Reusable Workflows is on another new level. Right, let's see how to create a...
Read more >
Musings on GitHub Actions Reusable Workflows
env variables set in the calling workflow are not accessible to the called workflow. The only parameter types that are supported are string...
Read more >
GitHub Actions
Action — An action is a reusable unit of code that performs a specific task within a workflow. Actions can be predefined and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

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