Detached pipelines with one job for branch pipelines

Hi everyone.

I have a job in my CI that should be executed automatically on master and manually on every other branch. It looks like this:

deploy-dev:
stage: deploy-dev
extends: .deploy
variables:
ENVIRONMENT: dev
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
when: always
- if: $CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH
when: manual

It works, but for every pipeline that runs for a branch there is a normal pipeline and a detached pipeline with only that job created. It’s a last job in this pipeline.

Zrzut ekranu 2021-03-10 170229

I read that something similar happened with merge requests but in this case merge requests don’t create any detached pipelines.

We are running GitLab Enterprise Edition 13.9.1-ee

Any advice on how to get rid of those detached pipelines?

Thanks

Hi @troyl
the first one is detached pipeline for Merge Request 275, the second one is pipeline for the branch.
You need to add rule not to create the job for MR pipelines.

rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
  when: never
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
  when: always
- if: $CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH
  when: manual

or you can disable MR pipelines completely by using workflow. Add this to the top of your .gitlab-ci.yml file.

workflow:
  rules:
    - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
      when: never
    - when: always

Hi @balonik
Just a question then, why would a merge request pipeline be created if no merge request was created?
both pipelines form my post were created after code was pushed to a branch. When an actual merge request is created there is only one pipeline created without any detached.

According to that screenshot you have MR 275 opened for that branch.

And this is the problem. There was no merge request at that time, I created one to merge this change the next day. As I wrote in the original post. Detached pipelines are created when anyone pushes to any branch.

Workflow rules might be useful to you here.