<ul>
<li>IMO, you should use <code>workflow</code> keyword. See <a href="https://docs.gitlab.com/ee/ci/yaml/workflow.html" rel="nofollow noreferrer">Doc</a>.</li>
<li><code>Rules</code> keyword is evaluated at the <code>job</code> level not at the <code>include</code>.</li>
</ul>
<pre><code>variables:
  NATIVE_COMPILE: &quot;true&quot;

workflow:
  rules:
    - if: '$NATIVE_COMPILE == &quot;true&quot;'

include:
  - project: 'pipelines/cicd'
    ref: improve/simplificando-pipes
    file: 'libraries/bundle/java/maven/.gitlab-ci-native.template.yml'

</code></pre>

CC BY-SA 4.0
2024-08-27T08:33:54.310Z
2024-08-27T08:33:54.310Z
YassineLbk
<p>Add the variable as a global project variable so that you can get its value in the linked yml file.</p>
<p>Settings -&gt; CI/CD -&gt; Variables</p>

CC BY-SA 4.0
2024-03-27T04:58:49.907Z
2024-03-27T04:58:49.907Z
serj
<p>Why my pipeline doesn't work? I just want to include this .yml if &quot;NATIVE_COMPILE&quot; is &quot;true&quot;:</p>
<pre class="lang-yml prettyprint-override"><code>variables:
  NATIVE_COMPILE : &quot;true&quot;
include:
  - project: 'pipelines/cicd'
    ref: improve/simplificando-pipes
    file: 'libraries/bundle/java/maven/.gitlab-ci-native.template.yml'
    rules:
      - if: $NATIVE_COMPILE == &quot;true&quot;
</code></pre>
<p>If I use something like this:</p>
<pre class="lang-yml prettyprint-override"><code>include:
  - project: 'pipelines/cicd'
    ref: improve/simplificando-pipes
    file: 'libraries/bundle/java/maven/.gitlab-ci-native.template.yml'
    rules:
      - if $CI_COMMIT_MESSAGE =~ /.*--native-compile*/
</code></pre>
<p>And I write <code>--native-compile</code> on commit, it works perfectly. But with my variables, it doesn't work. Why?</p>

<gitlab><cicd><yaml>
Why I can't include a .yml in CI/CD, using rules with mine variables?
Alan Michel
# Why I can't include a .yml in CI/CD, using rules with mine variables?

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

Why my pipeline doesn't work? I just want to include this .yml if "NATIVE_COMPILE" is "true":
variables:
  NATIVE_COMPILE : "true"
include:
  - project: 'pipelines/cicd'
    ref: improve/simplificando-pipes
    file: 'libraries/bundle/java/maven/.gitlab-ci-native.template.yml'
    rules:
      - if: $NATIVE_COMPILE == "true"

If I use something like this:
include:
  - project: 'pipelines/cicd'
    ref: improve/simplificando-pipes
    file: 'libraries/bundle/java/maven/.gitlab-ci-native.template.yml'
    rules:
      - if $CI_COMMIT_MESSAGE =~ /.*--native-compile*/

And I write --native-compile on commit, it works perfectly. But with my variables, it doesn't work. Why?

**Tags:** gitlab, cicd, yaml


---

## 2 answers

### Answer by username_1 on 2024-08-27. Score: 0

IMO, you should use workflow keyword. See Doc.
Rules keyword is evaluated at the job level not at the include.

variables:
  NATIVE_COMPILE: "true"

workflow:
  rules:
    - if: '$NATIVE_COMPILE == "true"'

include:
  - project: 'pipelines/cicd'
    ref: improve/simplificando-pipes
    file: 'libraries/bundle/java/maven/.gitlab-ci-native.template.yml'


---

### Answer by username_2 on 2024-03-27. Score: 0

Add the variable as a global project variable so that you can get its value in the linked yml file.

Settings -> CI/CD -> Variables


---

