HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

Run GitLab job only if variable is provided

Submitted by: @import:stackexchange-devops··
0
Viewed 0 times
gitlabprovidedonlyvariablejobrun

Problem

I have two jobs in my gitlab ci pipeline 'job a' and 'job b'. I want only 'job a' to run if variable x is provided and run 'job b' if variable b isn't provided.
Something like this.

job a:
  rule:
    - if: variable X is provided
  script:
    - do something

job b:
  rule:
    - if: variable X is not provided
  script:
    - do something

Solution

If you are OK with considering an empty variable value equivalent to it not being "provided", you can do this:
if: $x == ''


for "not provided" and
if: $x != ''


for "provided".

Context

StackExchange DevOps Q#17469, answer score: 2

Revisions (0)

No revisions yet.