How to use workflow env variables in job ifs?

env:
  IS_PUSH: github.event_name == 'push'

jobs:
  ci:
    if: ${{ env.IS_PUSH }}

This returns an error: “Unrecognized named-value: ‘env’”

env:
  IS_PUSH: github.event_name == 'push'

jobs:
  ci:
    steps:
      - if: ${{ env.IS_PUSH }}
        uses: mathieudutour/github-tag-action@v5

This works.

According to the GitHub Docs:

A map of environment variables that are available to all jobs and steps in the workflow.

What am I missing ?
Also what is the object name for the workflow context and is it accessible i.e. workflow.env.variable ?

There’s a conflicting statement about the env context:

You can only use the env context in the value of the with and name keys, or in a step’s if conditional.

https://docs.github.com/en/free-pro-team@latest/actions/reference/context-and-expression-syntax-for-github-actions#env-context

The other section might need to be changed to:

A map of environment variables that are available to the steps of all jobs in the workflow.

2 Likes

Thank you.

It definitely works the way it is explained in the link you provided.

My PR to make clear that the env context is only available in steps just landed: Actions: env context cannot be used in job.<job_id>.if (#1803) · github/docs@ad5c362 · GitHub

2 Likes