AACosgrove
AACosgrove

Reputation: 95

Overriding external gitlab.yml file

Suppose we have a .gitlab-ci.yml file that reads in a common.gitlab-ci.complete.yml file:

include: common.gitlab-ci.complete.yml

Suppose that common.gitlab-ci.complete.yml has the following stages:

stages:
  - build
  - unit-test
  - mutation-test

In the .gitlab-ci.yml file, how do we ignore the unit-test and mutation-test stages? Would it be something like:

include: common.gitlab-ci.complete.yml
stages:
  - build
  #- unit-test
  #- mutation-test

Would these stages override the one in the common.gitlab-ci.complete.yml file?

Upvotes: 1

Views: 4799

Answers (1)

ahogen
ahogen

Reputation: 840

(I have not yet checked this code for accuracy. Treat it as pseudocode.)

You're asking to remove all jobs in a stage. If you look at the documentation for the include: keyword, you'll note that the YAML is always merged with your current CI script. So no, you can't just add a statement like "Disable all jobs in stage A".

Here's an idea... recall that

If a stage is defined but no jobs use it, the stage is not visible in the pipeline...

https://docs.gitlab.com/ee/ci/yaml/#stages

So what you could do is add a mechanism for disabling all jobs in that stage. Then the stage will disappear as well. That mechanism might be checking a variable in rules.

So if you wrote the common.gitlab-ci.complete.yml with templates that check a variable to disable the job...

stages:
  - build
  - unit-test
  - package

.unit-test-stage:
  stage: unit-test
  when: on_success
  rules:
    - if: $DISABLE_UNIT_TESTS
      when: never

unit-test-job-a:
  extends: .unit-test-stage
  script:
    - echo "do stuff"

unit-test-job-b:
  extends: .unit-test-stage
  script:
    - echo "do more stuff"

Then maybe your top-level .gitlab-ci.yml would simply set that known variable in its global variables section like this:

include: common.gitlab-ci.complete.yml

variables:
  DISABLE_UNIT_TESTS: 1

Upvotes: 3

Related Questions