Answers: <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>
  
Answers: CC BY-SA 4.0
Answers: 2023-02-20T20:15:43.487Z
Answers: 2023-02-20T20:15:43.487Z
Answers: l0b0
Body: <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>
  
Tags: <gitlab><cicd>
Title: Run GitLab job only if variable is provided
UserDisplayName: Alan
ThreadText: # 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:
  
  ```yaml
  if: $x == ''
  
  ```
  
  for "not provided" and
  
  ```yaml
  if: $x != ''
  
  ```
  
  for "provided".
  
  
  ---
  
  