- Types of merge request pipelines
- Prerequisites
- Use
rules
to add jobs - Use
only
to add jobs - Use with forked projects
- Available predefined variables
- Troubleshooting
Merge request pipelines
You can configure your pipeline to run every time you commit changes to a branch.
This type of pipeline is called a branch pipeline.
Alternatively, you can configure your pipeline to run every time you make changes to the
source branch for a merge request. This type of pipeline is called a merge request pipeline.
Branch pipelines:
Merge request pipelines:
Both of these types of pipelines can appear on the Pipelines tab of a merge request.
The three types of merge request pipelines are:
To use merge request pipelines:
You can use the You can also use the You can use the External contributors who work in forks can’t create pipelines in the parent project.
A merge request from a fork that is submitted to the parent project triggers a
pipeline that:
Pipelines for forks display with the fork badge in the parent project:
Project members in the parent project can choose to run a merge request pipeline
for a merge request submitted from a fork project. This pipeline:
Run pipelines in fork project MRs to ensure that the post-merge pipeline passes in
the parent project. Additionally, if you do not trust the fork project’s runner,
running the pipeline in the parent project uses the parent project’s trusted runners.
Prerequisites:
To run a pipeline in the parent project for a merge request from a fork project:
When you use merge request pipelines, you can use:
If you get duplicate pipelines in merge requests, your pipeline might be configured
to run for both branches and merge requests at the same time. Adjust your pipeline
configuration to avoid duplicate pipelines.
In ,
you can add If you push an invalid CI/CD configuration to a merge request’s branch, two failed
pipelines appear in the pipelines tab. One pipeline is a failed branch pipeline,
the other is a failed merge request pipeline.
When the configuration syntax is fixed, no further failed pipelines should appear.
To find and fix the configuration problem, you can use:
It’s possible to have both branch pipelines and merge request pipelines in the
Pipelines tab of a single merge request. This might be by configuration,
or by accident.
If both types of pipelines are in one merge request, the merge request’s pipeline
is not considered successful if:
When using the merge when pipeline succeeds
feature and both pipelines types are present, the merge request pipelines are checked,
not the branch pipelines.
Types of merge request pipelines
merge request
label to indicate that the
pipeline ran only on the contents of the source branch, ignoring the target branch.
In GitLab 14.8 and earlier, the label is detached
.
Prerequisites
Use
rules
to add jobs
rules
keyword to configure jobs to run in
merge request pipelines. For example:
job1:
script:
- echo "This job runs in merge request pipelines"
rules:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
workflow: rules
keyword
to configure the entire pipeline to run in merge request pipelines. For example:
workflow:
rules:
- if: $CI_PIPELINE_SOURCE == 'merge_request_event'
job1:
script:
- echo "This job runs in merge request pipelines"
job2:
script:
- echo "This job also runs in merge request pipelines"
Use
only
to add jobs
only
keyword with merge_requests
to configure jobs to run in merge request pipelines.
job1:
script:
- echo "This job runs in merge request pipelines"
only:
- merge_requests
Use with forked projects
Run pipelines in the parent project
Available predefined variables
Troubleshooting
Two pipelines when pushing to a branch
workflow:rules
to switch from branch pipelines to merge request pipelines.
After a merge request is open on the branch, the pipeline switches to a merge request pipeline.
Two pipelines when pushing an invalid CI/CD configuration file
The merge request’s pipeline is marked as failed but the latest pipeline succeeded