9

Is it possible to use variables inside global env sections in github workflows? Something like following code snippet

env:
  isqa: ""
  local_tag: "${{env.isqa}}latest"
  project: "important"
  aws_taskdef: "project-${project}-something"

1 Answer 1

12

You cannot put these env references on the same level, but you can specify the to-be-referenced values on the workflow or job level, and reference them in the step level. It would be something like this

jobs:
  test:
    runs-on: ubuntu-latest
    env:
      IS_QA: "qa"
      PROJECT: "important"
    steps:
      - run:
          echo ${{env.IS_QA}}
          echo ${{env.LOCAL_TAG}}
          echo ${{env.PROJECT}}
          echo ${{env.AWS_TASKDEF}}
        env:
          LOCAL_TAG: "${{env.IS_QA}}-latest"
          AWS_TASKDEF: "project-${{env.PROJECT}}-something"

You can see my testing in here, https://github.com/chenrui333/github-action-test/blob/main/.github/workflows/env-test.yaml

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

3 Comments

runs-on: doesn't support env so for example runs-on: ${{env.OS_VERSION}} will not work
Based on this doc page runs-on: does support env: docs.github.com/en/actions/learn-github-actions/…
At least on my tests, it only works with env at the step level and not the job level.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.