gitlabgitlab-ci

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?


Solution

  • You can include the same file multiple times, but you need to disambiguate the names of jobs, so they don't overwrite each other.

    Example .gitlab-ci.yml:

    include:
      - local: "child.yml"
        inputs:
          branch: release/1.37
      - local: "child.yml"
        inputs:
          branch: master
    

    Example child.yml:

    spec:
      inputs:
        branch:
          description: "The corresponding branch to consider"
          type: string
    
    ---
    # IMPORTANT CHANGE HERE!
    # The input value is used in the branch name in order to set
    # it apart from other includes of the same file.
    build-$[[ inputs.branch ]]:
      script:
        - env -0 | sort -z | xargs -0 -n1 echo