Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GitHub Actions - workflow environment variable values dependent on environment

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'
like image 684
Keith C Avatar asked May 21 '26 22:05

Keith C


1 Answers

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.

like image 61
Grzegorz Krukowski Avatar answered May 27 '26 11:05

Grzegorz Krukowski



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!