3

I am looking to have a set of workflow level environment variables that take different values depending on the environment the workflow is running on. Below is how I am looking to do this:

name: Test workflow file

on:
  workflow_dispatch

env:
  GH_ENV_VAR: ${{ contains(github.ref, 'main') && 'prod' || contains(github.ref, 'feature-branch') && 'dev' || 'cert' }}
  GH_ENV_VARIABLE: ${{ env.GH_ENV_VAR == 'dev' && 'DEV' || 'DO NOT KNOW'}} 
  USER_ACCOUNT: sample
  WAREHOUSE: small

I am seeing the following error:

Invalid workflow file

The workflow is not valid. .github/workflows/workflow-file.yml (Line: 8, Col: 20): Unrecognized named-value: 'env'. Located at position 1 within expression: env.GH_ENV_VAR == 'dev' && 'DEV' || 'DO NOT KNOW'

1 Answer 1

1

You cannot use env. scope when creating env variables.

Even though it may look ok and you expect to have GH_ENV_VAR already there - it's not possible in workflows.

Sign up to request clarification or add additional context in comments.

2 Comments

I found that a workaround of setting outputs in a setup job in all other jobs of a workflow works for me. I referred to documentation provided here: docs.github.com/en/actions/using-jobs/defining-outputs-for-jobs
Here's an example of the workaround implementation: github.com/orgs/community/discussions/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.