2

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.

danielnelz
  • 3,794
  • 4
  • 25
  • 35
elsamuko
  • 668
  • 6
  • 16

1 Answers1

2

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.

Tolis Gerodimos
  • 3,782
  • 2
  • 7
  • 14