Accessing environment variable

Hello, I have defined a variable and I want to access it from a if statement:

---
name: deploy
on:
  push:
    branches:
      - master
env:
  ALLOWED_OWNER: theforeman
  
publish:
  if: github.repository_owner == ${{ env.ALLOWED_OWNER }}
  ...

But I am getting: The workflow is not valid. .github/workflows/deploy.yml (Line: 87, Col: 9): Unrecognized named-value: ‘env’. Located at position 1 within expression: env.ALLOWED_OWNER

What is wrong? Thanks

The if condition is syntactically wrong, the entire expression must be wrapped in ${{ }} or not at all.

But that aside, you cannot reference the env context here:

You can use the env context in the value of any key in a step except for the id and uses keys.

1 Like

Damn, thanks.

I need to run two of our jobs on the same conditions, it is a complex query unfortunately and I want to share it somewhere.

This post was flagged by the community and is temporarily hidden.

This post was flagged by the community and is temporarily hidden.

This post was flagged by the community and is temporarily hidden.

Your best bet for something like that is probably to have a job that calculates the condition as an output, then the other jobs needs the first one and access the output via needs.first-job.outputs.whatever.

1 Like