<p>If you are OK with considering an empty variable value equivalent to it not being &quot;provided&quot;, you can do this:</p>
<pre class="lang-yaml prettyprint-override"><code>if: $x == ''
</code></pre>
<p>for &quot;not provided&quot; and</p>
<pre class="lang-yaml prettyprint-override"><code>if: $x != ''
</code></pre>
<p>for &quot;provided&quot;.</p>

CC BY-SA 4.0
2023-02-20T20:15:43.487Z
2023-02-20T20:15:43.487Z
l0b0
<p>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.</p>
<pre><code>job a:
  rule:
    - if: variable X is provided
  script:
    - do something

job b:
  rule:
    - if: variable X is not provided
  script:
    - do something
</code></pre>

<gitlab><cicd>
Run GitLab job only if variable is provided
Alan
# Run GitLab job only if variable is provided

(Asked by: username_0 on 2023-02-20)

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

**Tags:** gitlab, cicd


---

## 1 answers

### Answer by username_1 on 2023-02-20. Score: 2

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".


---

