简体   繁体   中英

Run gitlab pipeline only for commits

Currently gitlab runs a pipeline when creating a merge request + branch with the GUI.
Is it possible to skip this pipeline, since it's only repeats the last pipeline from the default branch?

We tried with:

workflow:
  rules:
    - if: $CI_MERGE_REQUEST_IID
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH

This works to skip new branch pipelines, but it doesn't run a pipeline for new commits on branches which have no merge request.

In order to stop pipeline execution when a new branch is created and in the same time run when a new commit happens on a branch

Try change from:

workflow:
  rules:
    - if: $CI_MERGE_REQUEST_IID
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH

To

workflow:
  rules:
    - if: $CI_COMMIT_BEFORE_SHA == "0000000000000000000000000000000000000000"
      when: never
    - if: $CI_MERGE_REQUEST_IID
    - if: $CI_PIPELINE_SOURCE == "push"

The rule

- if: $CI_COMMIT_BEFORE_SHA == "0000000000000000000000000000000000000000"
  when: never

Will stop the execution of a new pipeline when a new branch is created

The rule

- if: $CI_PIPELINE_SOURCE == "push" 

This is added to allow a new pipeline trigger when a commit happens on branch, because if the event is not a merge request the pipeline won't execute.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM