Skip to content

Gitlab-CI rules if condition; variable does not exist

I'm migrating off only: and except: and switched to rules. However, I'm finding difficulty testing for whether a variable exists.

Use case: Team wants to manually build/promote and deploy by referencing a commit, tag or branch and specifying a ENV variable for which it will be deployed. Team wants to generally follow GitFlow where develop pushes to DEVINT, release/* pushes to SIT, and master pushes to Production.

In order to filter this I check:

rules:
    - if: $ENV == "DEVINT" || $CI_COMMIT_BRANCH == "develop" && !$ENV # Only run if this is setup
      when: always

!ENV didn't seem to work so for now I've set a Group variable so ENV = "null".

Is there recommended syntax for testing if a variable exists?

THanks