Github Workflow: How to conditionally setup ENV for all subsequent Jobs?

At the start of my workflow I want to conditionally set values for some ENV variables. These values should be global and apply to all jobs and steps. The following code is structurally invalid but it’s what I’m trying to accomplish

if: github.ref_name == "target branch"  (for example)
  env:
    var1: 'Right Branch'

if: github.ref_name != "target branch" 
  env:
    var1: 'Wrong Branch'

jobs:
  ...

you could do something like:

echo VAR1="Right Branch" >> $GITHUB_ENV

or

echo VAR1="Wrong Branch" >> $GITHUB_ENV

as a step.

Alternatively, you could probably use jobs.id.outputs.var1

Something like:

env:
  var1: ${{ jobs.something.outputs.var1 }}

This syntax could be very wrong, I don’t do it too often. You can see me using somewhat related pieces here:

Thanks! $GITHUB_ENV is what I was missing. FWIW stackoverflow gave me a great answer including sample code. Github Workflow: How to conditionally setup ENV for all subsequent Jobs? - Stack Overflow

I suggest you using the strategy matrix for the right environment you want to set . Especially if you have the Actions environment set in your repo.

Looks interesting. Can I use Strategy in a Pipeline context? I only want to run -one- variant at a time. Eg. a push to branch X only runs config X, push to Y run config Y. Most of what I’m configuring is security credentials to access different target environments. Dev deploys, then QA, Staging and eventually Prod.