3 child file included in a GitLab pipeline but only logs for the third include

I work on a GitLab pipeline and from the gitlab-ci.yml file, I include 3 times the same child file but with different inputs.

In the child file, there is a stage (display) called everytime and it currently displays values for inputs.

When the pipeline executes, I see only logs from the third include and not for the 2 firsts.

I mean that I see $branch is equals to “master” but not to “develop” or “release/1.37”.

How is it possible?

Below is my gitlab-ci.yml file:

spec:
  inputs:
    RunAllApexTests:
      description: "Run all apex tests"
      type: boolean
      default: false
---
include:
  - local: "ci/deploy.gitlab-ci.yml"
    inputs:
      branch: develop
      run_all_apex_tests: $[[ inputs.RunAllTests ]]
  - local: "ci/deploy.gitlab-ci.yml"
    inputs:
      branch: release/1.37
  - local: "ci/deploy.gitlab-ci.yml"
    inputs:
      branch: master

And now is my child file (ci/deploy.gitlab-ci.yml):

spec:
  inputs:
    branch:
      description: "The corresponding branch to consider"
      type: string
      regex: ^(master|develop|release\/.*)$
    run_all_apex_tests:
      description: "Run all apex tests"
      type: string
      default: "false"
---

stages:
  - display

.base-deploy:
  variables:
    branch: $[[ inputs.branch ]]
    runAllApexTests: $[[ inputs.run_all_apex_tests ]]

display:
  stage: display
  extends: .base-deploy
  script:
    - echo "Stage display";
    - echo $runAllApexTests;
    - echo $branch;

And below are the logs:

$ echo "Stage display";
Stage display
$ echo $runAllApexTests;
false
$ echo $branch;
master

Does it mean the 2 first include are not executed?

Yes — it means the first two includes are not being executed.

Why?

In GitLab CI, when you use multiple includes of the same file with different inputs, only the last one actually gets executed, unless you’re defining separate jobs per include.

Right now, all three includes are overwriting each other — so only the last one (branch: master) survives in the pipeline.


How to Fix It

You need to parameterize and create separate jobs for each include. GitLab doesn’t automatically “duplicate” jobs for each include like a loop — you must define distinct job names and structures.


:white_check_mark: Correct Approach (Define jobs explicitly):

gitlab-ci.yml:

include:
  - local: "ci/deploy.gitlab-ci.yml"

deploy-develop:
  extends: .base-deploy
  variables:
    branch: develop
    runAllApexTests: "false"
  stage: display

deploy-release:
  extends: .base-deploy
  variables:
    branch: release/1.37
    runAllApexTests: "false"
  stage: display

deploy-master:
  extends: .base-deploy
  variables:
    branch: master
    runAllApexTests: "false"
  stage: display

ci/deploy.gitlab-ci.yml:

.base-deploy:
  script:
    - echo "Stage display"
    - echo $runAllApexTests
    - echo $branch

TL;DR

  • Yes, the first two includes are ignored.
  • GitLab only keeps the last include unless you define distinct jobs.
  • Define jobs explicitly to execute the logic multiple times with different inputs.

Let me know if you want to keep the inputs: structure — it can be done using GitLab’s component reuse or workflow:rules.