zb226
zb226

Reputation: 10539

How to quickly disable / enable stages in Gitlab CI

When you work on your .gitlab-ci.yml for a big project, for example having a time consuming testing stage causes a lot of delay. Is there an easy way to disable that stage, as just removing it from the stages definition, will make the YAML invalid from Gitlab's point of view (since there's a defined but unused stage), and in my case results in:

test job: chosen stage does not exist; available stages are .pre, build, deploy, .post

Since YAML does not support block comments, you'd need to comment out every line of the offending stage.

Are there quicker ways?

Upvotes: 87

Views: 103545

Answers (5)

Marcel Šerý
Marcel Šerý

Reputation: 316

Best way to "comment-out" whole stage in a single line is to have the stage description inside an individual file and commenting-out the include line.

See Gitlab docs on Include directive. This file splitting approach is generally very useful for big gitlab-ci files.

For example:

# .gitlab-ci.yml

include:
  - local: ".gitlab-ci.build.yml"
# Temporarily disabled
#  - local: ".gitlab-ci.test.yml"
  - local: ".gitlab-ci.release.yml"

Upvotes: 6

Inshaf Mahath
Inshaf Mahath

Reputation: 683

Also possible with rules and when as below:

test:
  stage: test
  rules:
   - when: never

Upvotes: 68

Christophe Muller
Christophe Muller

Reputation: 5110

You could disable all the jobs from your stage using this trick of starting the job name with a dot ('.'). See https://docs.gitlab.com/ee/ci/jobs/index.html#hide-jobs for more details.

.hidden_job:
  script:
    - run test

Upvotes: 113

yallie
yallie

Reputation: 2530

There is a way to disable individual jobs (but not stages) like this:

test:
  stage: test
  when: manual

The jobs are skipped by default, but still can be triggered in the UI:

Gitlab CI screenshot

Upvotes: 77

zb226
zb226

Reputation: 10539

So far, the easiest way I've found is to use a rules definition like so:

test:
  stage: test
  rules:
    - if: '"1" != "1"'
(...)

This still feels a bit odd, so if you have a better solution, I'll gladly accept another answer.

Upvotes: 4

Related Questions