Merge Request Pipelines, Merged Results Pipelines, Merge Trains, and Pre-Merge Validation: Concepts, Architecture, and Mental Model
A green pre-merge pipeline is meaningful only if you can name the exact code state it evaluated. This lesson separates branch pipelines, merge request pipelines, merged-results pipelines, and merge-train pipelines; maps the source/target/ref/SHA evidence for each; and explains when protected variables or runners are—and are not—available.
Learning objectives
- Distinguish branch, merge request, merged-results, and merge-train pipelines by the code state and integration context they evaluate.
- Record pipeline source, MR/source/target metadata, MR ref path, exact pipeline SHA, and merge-request event type as separate evidence fields.
- Explain why ordinary merge request pipelines validate source-branch content while merged-results pipelines validate a temporary merged commit.
- Explain the current protected-variable/runner conditions for merge request pipelines and why fork merge requests require a stronger trust boundary.
- Connect pre-merge evidence to mergeability without treating a green pipeline as proof that every merge policy or external system is healthy.
1. The practical problem: “green” is meaningless without the code identity
Chapter 15 coordinated pipelines across projects. Chapter 16 moves the trust boundary back to the moment before code enters an authoritative branch. A merge request can have a green branch pipeline, a green merge request pipeline, a green merged-results pipeline, or a green merge-train pipeline. Those states are not interchangeable because each can evaluate a different Git ref and integration context.
The first question for every pre-merge result is therefore not “did it pass?” but “what exact source revision and integration state did this pipeline evaluate?” Only after that identity is known should you interpret test results, protected-resource access, or mergeability.
2. Mental model: from MR event to mergeability evidence
A merge request is a relationship between source and target branches plus review/approval state. GitLab can build different pipeline views of that relationship. Ordinary MR pipelines validate the source branch content. Merged-results pipelines synthesize a temporary commit that combines source and target. Merge trains go further by validating a candidate together with earlier merge requests in the queue.
flowchart TD
A[Merge request event] --> B[Source and target metadata]
B --> C{Pipeline mode}
C -->|MR| D[Source branch content]
C -->|Merged result| E[Temporary source plus target commit]
C -->|Merge train| F[Temporary queued integration commit]
D --> G[Checks and reports]
E --> G
F --> G
G --> H[Mergeability evidence]
H --> I[Merge policy decision]
The arrows matter. Pipeline creation is separate from job inclusion; job success is separate from report ingestion; a successful pipeline is separate from approvals, conflicts, merge-train position, and the health of any later deployment.
3. Four pipeline types, four different claims
| Pipeline type | Tier | Code state under test | Primary claim |
|---|---|---|---|
| Branch pipeline | Free / Premium / Ultimate | Branch commit | This branch revision passed these checks. |
| Merge request pipeline | Free / Premium / Ultimate | MR source-branch content | This MR source revision passed these MR-scoped checks. |
| Merged-results pipeline | Premium / Ultimate | Temporary merged commit of source + target | This MR currently integrates with the target branch under this synthetic commit. |
| Merge-train pipeline | Premium / Ultimate | Temporary integration commit including earlier queued MRs | This candidate works in the queue order GitLab is validating. |
GitLab documents MR pipelines as source-branch validation: they do
not automatically test the target branch content. That is exactly
why merged-results pipelines exist. Merge trains solve a different
race: two MRs can each integrate with
main independently yet conflict when they land close
together.
4. The evidence tuple for pre-merge CI
For this chapter, treat the following as one evidence record rather than as unrelated variables:
ID, source, status, created/finished timestamps
CI_COMMIT_SHA and ref/ref-path actually checked out
IID, source project/branch, target project/branch
CI_MERGE_REQUEST_EVENT_TYPE: detached, merged_result, or merge_train when available
Source/target branch SHAs where GitLab exposes them
Fork/same-project origin, protected branch/resource state, triggering user context
Do not assume CI_MERGE_REQUEST_SOURCE_BRANCH_SHA is
always populated. Current GitLab documents it as empty in ordinary
merge request pipelines and populated in merged-results pipelines.
The pipeline’s own CI_COMMIT_SHA remains the central
identity of what the runner checked out.
5. MR pipelines are opt-in configuration, not a branch-pipeline alias
Branch pipelines can exist with no special rules. Merge request
pipelines require the root project configuration to create work for
CI_PIPELINE_SOURCE == "merge_request_event". Current
GitLab documentation explicitly requires matching
rules or workflow:rules in the project’s
.gitlab-ci.yml; a matching rule hidden only inside an
included component is not enough to satisfy the MR-pipeline
prerequisite.
workflow:
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
- when: never
validate:
image: alpine:3.22.1
script:
- printf 'source=%s\nsha=%s\n' "$CI_PIPELINE_SOURCE" "$CI_COMMIT_SHA"
This allowlist creates one intentional MR pipeline for an MR update and a separate default-branch pipeline after merge. It does not create a feature-branch push pipeline in parallel with the MR pipeline.
6. MR ref paths and temporary integration commits
Ordinary MR pipelines expose an MR ref path such as
refs/merge-requests/1/head through
CI_MERGE_REQUEST_REF_PATH. This is useful evidence when
later jobs or downstream pipelines need to identify the MR pipeline
rather than the latest branch pipeline.
Merged-results pipelines instead build a temporary merged commit
generated by GitLab. That commit is not the head of either source or
target branch. For audit purposes, record
CI_COMMIT_SHA, MR source/target names, and
CI_MERGE_REQUEST_EVENT_TYPE together; do not replace
the synthetic SHA with the source branch SHA in your evidence.
7. Protected variables and runners are a trust decision
Protected resources are not ordinary configuration convenience. Current GitLab lets maintainers control whether merge request pipelines can access protected CI/CD variables and protected runners. Access is restricted: the source and target branches must both be protected, both must belong to the same project, and the user triggering the pipeline must have the required access to the target branch.
A fork MR cannot satisfy the same-project requirement. This is intentional. Unreviewed code from a fork must not acquire deployment credentials or privileged runner access just because somebody opened a merge request.
8. Fork merge requests change where code and resources come from
By default, an MR from a fork runs its pipeline in the fork project using the fork’s CI configuration, runners, and variables. An authorized member of the parent project can choose to run the MR pipeline in the parent project instead. That changes the resource boundary: the pipeline uses the fork branch’s CI configuration but the parent project’s settings/resources and the triggering member’s permissions.
This can be useful when the fork runner is untrusted, but it is also dangerous: malicious CI changes in the fork can try to exfiltrate parent-project resources. GitLab therefore warns in the UI. The safe operating model is explicit review of CI/configuration changes before any parent-project execution, plus no protected-resource exposure unless all documented requirements are met.
9. Merged results answer an integration question that MR pipelines cannot
An ordinary MR pipeline asks “does this source revision pass?” A merged-results pipeline asks “does a temporary merge of this source revision with the current target pass?” That catches integration defects that do not exist on either branch alone.
Current GitLab places merged-results pipelines in Premium/Ultimate. The mandatory course path must therefore not depend on the feature. You will simulate the same conceptual question locally with a temporary merge in Lesson 2 and label that evidence as a simulation rather than as a GitLab merged-results pipeline.
10. Merge trains add queue context
A merged-results pipeline considers one MR against the target branch. A merge train considers the candidate together with merge requests ahead of it in the queue. That makes the tested integration state dependent on train order. When an earlier MR merges or drops from the train, later candidates can be re-evaluated.
Current GitLab merge trains are Premium/Ultimate and use
merged-results pipeline mechanics. The pipeline source remains
merge-request-oriented; CI_MERGE_REQUEST_EVENT_TYPE is
the more precise signal for detached MR, merged result, or
merge-train context.
11. Read-only inspection before changing anything
- Record project path, MR IID, source project/branch, and target project/branch.
- Open the pipeline and record pipeline ID, source, ref, SHA, and status.
- Inspect the compiled configuration and identify the workflow rule that created the pipeline.
-
Record
CI_MERGE_REQUEST_EVENT_TYPEandCI_MERGE_REQUEST_REF_PATHwhen present. - Determine whether the source is a same-project branch or a fork.
- Inspect whether source/target refs are protected and whether protected resources are enabled for MR pipelines—without exposing any secret values.
- Only then interpret the green/red pipeline as merge evidence.
12. Misconceptions to remove
| Misconception | Correction |
|---|---|
| “MR pipeline means source+target integration.” | Ordinary MR pipelines run on source-branch content. Merged-results pipelines test a temporary merge. |
| “Green branch pipeline is the same as green MR pipeline.” | They can have different rules, variables, refs, and trust context. |
| “Protected variable means safe to expose in every MR.” | Protected-resource access has strict branch/project/user conditions and remains a security-sensitive choice. |
| “Fork pipelines are just slower parent pipelines.” | Fork pipelines normally execute in the fork project; parent-run fork pipelines change the resource boundary and require explicit trust review. |
| “Merge train success proves production is healthy.” | It proves the queued integration candidate passed configured checks; deployment and external health are later states. |
Knowledge check
What is the main evidence difference between an ordinary MR pipeline and a merged-results pipeline?
An ordinary MR pipeline validates source-branch content; a merged-results pipeline validates a GitLab-generated temporary commit that combines source and target. Record the actual pipeline SHA and event type.
Why is CI_MERGE_REQUEST_SOURCE_BRANCH_SHA not a universal MR evidence field?
GitLab documents it as empty in ordinary MR pipelines and populated in merged-results pipelines, so CI_COMMIT_SHA plus MR metadata is the safer universal starting point.
Can a fork MR access protected variables merely because its target branch is protected?
No. Current protected-resource access for MR pipelines requires both branches protected, same-project source/target, and appropriate user access. Fork MRs do not meet the same-project condition.
What does a merge train add beyond merged results?
It validates a candidate in queue context together with earlier merge requests that are expected to land first.
Why preserve pipeline ID and SHA before retrying?
A retry, rebase, push, or train requeue can change the integration state. The original IDs/SHA preserve the exact first-failure evidence.
Version and compatibility note
GitLab and GitLab Runner evolve continuously. Treat version-sensitive YAML, runner/executor behavior, APIs, security features, policy controls, tiers, and deprecations as assumptions to verify against the current official GitLab documentation before production use. Preserve the exact project/ref/SHA, compiled configuration, pipeline/job IDs, runner/tool versions, and external target evidence used for any reproducible lab or incident record.
Official references and version notes
Documentation verification date: 2026-09-11. Merge-request pipeline behavior, protected-resource access, merged-results pipelines, merge trains, predefined variables, and merge checks are version-sensitive. Re-check the deployed GitLab version and project settings before using these patterns in production.
- Merge request pipelines — prerequisites, source-branch behavior, fork pipelines, parent-project execution, and protected resources.
- Merged results pipelines — temporary merged commits and current Premium/Ultimate availability.
- Merge trains — queue semantics, temporary integration state, current parallel limits, and enforcement options.
- Types of pipelines — branch, MR, merged-results, merge-train, parent/child, and multi-project distinctions.
-
Predefined variables reference
— MR ref/source/target variables and
CI_MERGE_REQUEST_EVENT_TYPE. -
CI/CD YAML syntax reference
— authoritative
workflow:rules,rules,changes, and job semantics. - Debugging CI/CD pipelines — CI Lint, compiled configuration, pipeline naming, and evidence-first troubleshooting.
- Protected branches — permissions and CI/CD implications for protected refs.
Keep the academy open
Support free, practical DevOps education.
Every lesson is designed to remain readable in a browser, downloadable from GitHub, and usable without a paid learning platform. Contributions help expand and maintain the curriculum.
0x716c4Ab160C4B66F31a28AE2448BfF68fc3a2ef0
Send only Ethereum/ERC-20 compatible assets to this
address.