5

Environment variables from GitHub Environments are available in the vars context.

Sometimes you could have 5-6 variables in the vars context, and you would like to have them injected into the env context to use them in the steps. Is there an automated or easy way?

1 Answer 1

13

You can do it like this with toJSON and jq:

- name: Set vars to env
  env:
    VARS_JSON: ${{ toJSON(vars) }}
  run: |
    echo "$VARS_JSON" | jq -r 'keys[] as $k | "\($k)=\(.[$k])"' >> $GITHUB_ENV

- name: Check env vars
  run: |
    echo "VAR1=$VAR1"
    echo "VAR2=$VAR2"

Sample ouptut:

vars_to_env

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

Comments

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.