Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable pipeline for every commit in Gitlab and only run it on open merge request

Tags:

The CI pipeline runs on every commit in my Gitlab repository at work. Is there way to disable that and only run the CI pipeline on an open merge request to the master branch?

like image 930
jj123456 Avatar asked Jul 19 '18 20:07

jj123456


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 restrict merge in GitLab?

On the left sidebar, select Settings > Repository. Expand Protected branches. From the Branch dropdown list, select the branch you want to protect. From the Allowed to merge list, select a role, or group that can merge into this branch.

How do you trigger a pipeline on a merge request?

Push a new commit to the source branch for a merge request. Select Run pipeline from the Pipelines tab in a merge request. This option is only available when merge request pipelines are configured for the pipeline and the source branch has at least one commit.


2 Answers

There is currently no configuration option to do that. Here are some things that can be used to "disable" a pipeline build.

  • Adding [ci skip] inside the commit message will not trigger a pipeline on push.
  • Using except and only options on all jobs inside the pipeline. To avoid duplication in this case, you can use Anchors.

Update: GitLab 11.7

When pushing to GitLab you can skip triggering a pipeline by passing ci.skip option to the push command: git push -o ci.skip

like image 80
yamenk Avatar answered Sep 20 '22 10:09

yamenk


Update in 2020 because solution with only and except are candidates for deprecation : https://docs.gitlab.com/ee/ci/yaml/#onlyexcept-basic

Still in .gitlab-ci.yml you should use now rules : See https://docs.gitlab.com/ee/ci/yaml/#rules

I simply set this rule on my build job and the job is "blocked" and wait a manual trigger from the UI.

 rules:
   - when: manual

Note that we can create more advanced rules with conditions to trigger for exemple if we see a git tag.

https://docs.gitlab.com/ee/ci/yaml/#exclude-jobs-with-rules-from-certain-pipelines

like image 30
Maxence Avatar answered Sep 20 '22 10:09

Maxence