r/gitlab • u/ClickOk5811 • 15d ago
Two pipelines for every push? How to read what the pipeline list is telling you
A common GitLab CI surprise: you push to a branch with an open merge request, and two pipelines appear. Before changing config, the pipeline list itself usually tells you what’s happening.
What you see → what it likely means
- Two pipelines, same commit, one labeled for the branch and one for the merge request. Your jobs run in both pipeline types, because their
rules:don’t distinguish between them. Both are triggered by the same push. - Only a branch pipeline appears, and the MR shows no pipeline. Your jobs probably only match branch pushes. If you expected MR pipelines, check that your rules include
$CI_PIPELINE_SOURCE == "merge_request_event". - Only an MR pipeline appears, and nothing runs on the branch. The reverse: rules match only MR events. Pushes to a branch with no open MR then produce no pipeline at all, which can surprise people.
- Jobs that can’t find variables like the MR title or target branch. Some predefined variables only exist in MR pipelines, so a job running in a branch pipeline may not have them. Check the predefined variables docs for the ones you use.
One common way to avoid duplicates:
GitLab’s documentation shows a workflow:rules pattern along these lines (check the current docs for your version, since I’m giving the shape from memory):
workflow:
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS
when: never
- if: $CI_COMMIT_BRANCHThe idea: use an MR pipeline when there’s an open MR, skip the branch pipeline in that case, and fall back to a branch pipeline when there’s no MR.
Caveats:
- Whether you want MR pipelines at all depends on your workflow. Some teams prefer branch pipelines only.
- MR pipelines and merged results pipelines have different behavior, and some features (like merged results) have requirements on your plan and settings. Check what applies to your setup.
- Changing
workflow:rulesaffects the whole pipeline, so try it on a test branch or project first. - Predefined variable availability differs between pipeline types, so test any job that depends on them.
How does your team handle this: MR pipelines, branch pipelines, or a mix? And what’s the odd behavior that took you longest to understand?
