Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 221
zb226 Avatar asked Nov 24 '20 17:11

zb226


People also ask

How do I stop a running pipeline in GitLab?

To enable or disable GitLab CI/CD Pipelines in your project: Navigate to Settings > General > Visibility, project features, permissions. Expand the Repository section. Enable or disable the Pipelines toggle as required.

How do I skip CI GitLab?

Push options for GitLab CI/CD You can use push options to skip a CI/CD pipeline, or pass CI/CD variables. Do not create a CI pipeline for the latest push. Only skips branch pipelines and not merge request pipelines. Provide CI/CD variables to be used in a CI pipeline, if one is created due to the push.

What is used to restrict when a job is executed on your pipeline?

Run jobs for scheduled pipelines To configure a job to be executed only when the pipeline has been scheduled, use the rules keyword.


4 Answers

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
like image 110
Christophe Muller Avatar answered Oct 23 '22 22:10

Christophe Muller


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

like image 43
yallie Avatar answered Oct 23 '22 23:10

yallie


Also possible with rules and when as below:

test:
  stage: test
  rules:
   - when: never
like image 20
Inshaf Mahath Avatar answered Oct 23 '22 23:10

Inshaf Mahath


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.

like image 8
zb226 Avatar answered Oct 23 '22 21:10

zb226