CONFIG.SYS
  • ALL_POSTS.BAT
  • ABOUT.EXE

GitLab: Prevent ci pipeline on branch creation - Mon, Aug 22, 2022

GitLab: Prevent ci pipeline on branch creation

While trying to optimize the Pipeline-Runs for a specific GitLab repository through the usage of rules in the gitlab-ci.yml, I noticed that two identical pipelines were triggered when opening a merge request :

  • One pipeline is triggered when the branch for the merge request is created
  • One pipeline is triggered when the merge request itself is created

Since the later one was being triggered by an event of type merge_request_event which also triggers a pipeline when pushing a change to a branch of a merge request, I opted to remove the branch creation pipeline.
This turned out not to be that easy since the event type was push which starts a pipeline every time something is pushed. So I needed a different way to not run this pipeline. I fond the solution in this stackoverflow post .
The CI_COMMIT_BEFORE_SHA variable for new branches is all 0. So I combined both variables in the rule for the jobs in the pipeline:

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

Now I only have a single pipeline when opening a merge request. There is one downside however. The rule above also does not trigger a pipeline run when a new branch is pushed manually the the GitLab server.

Back to Home


21st century version | © Thomas Reuhl 2025 | Disclaimer | Built on Hugo

Linkedin GitHub