GItLab CI/CD add variable only for develop branch

Viewed 522

I have a GitLab project that uses include and variables for the pipeline for example:

include:
 - project: a/b
   file: /file.gitlab-ci.yml

variables:
  Test: test

now I want that only for the develop branch a new boolean variable will be added/only when the pipeline runs from develop branch it will be true

    variables:
     Test: test
     Say hello: true

How can I add this to my gitlab-ci file?

1 Answers

You'll want to use the variables keyword with the rules keyword to make this work. If you want it in your root configuration to have it impact every job, you'll use workflow keyword like this:

workflow:
  rules:
    - if: $CI_SOURCE_BRANCH == "develop"
      variables:
          TEST: true
          HELLO: true

If you want it to exist within just one job, use the same rules syntax but within just one job.

Related