doc/ci/pipelines/merge_request_pipelines.md
{{< details >}}
{{< /details >}}
You can configure your pipeline to run every time you make changes to the source branch in a merge request. This type of pipeline is called a merge request pipeline.
These pipelines run when you:
Merge request pipelines:
merge request label in pipeline lists.To run a pipeline that tests the result of merging the source and target branches together, use merged results pipelines.
To use merge request pipelines:
.gitlab-ci.yml file must include job rules or workflow rules that match CI_PIPELINE_SOURCE == "merge_request_event".To configure merge request pipelines, you must configure jobs in your
.gitlab-ci.yml file to run when CI_PIPELINE_SOURCE equals merge_request_event.
[!note] Rules defined in
include:(for example, withinclude:component) do not satisfy this requirement. You must define matchingrules:orworkflow: rulesdirectly in.gitlab-ci.yml.
You can configure individual jobs with rules,
or use workflow: rules to control the entire pipeline.
Use the rules keyword to configure individual 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"
You can also control when jobs run based on file changes:
test:
script:
- echo "This job always runs in merge request pipelines"
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
lint:
script:
- echo "This job runs only when JavaScript files change"
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
changes:
- "*.js"
Use the workflow: rules keyword
to configure all jobs in a 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"
For more workflow examples, see:
To use security scanning tools with merge request pipelines,
use the CI/CD variable AST_ENABLE_MR_PIPELINES or the latest template edition.
{{< history >}}
{{< /history >}}
If your .gitlab-ci.yml defines pipeline inputs, you can customize input values when
you manually run a new merge request pipeline. You can also set CI/CD variables in the same form.
Prerequisites:
.gitlab-ci.yml file must be configured for merge request pipelines..gitlab-ci.yml file must also define a spec: inputs section.To run a merge request pipeline with custom inputs:
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 trigger 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.
[!warning] Fork merge requests can contain malicious code that tries to steal secrets in the parent project when the pipeline runs, even before merge. As a reviewer, carefully check the changes in the merge request before triggering the pipeline. Unless you trigger the pipeline through the API or the
/rebasequick action, GitLab shows a warning that you must accept before the pipeline runs. Otherwise, no warning displays.
Prerequisites:
.gitlab-ci.yml file must be configured to
run jobs in merge request pipelines.To use the UI to run a pipeline in the parent project for a merge request from a fork project:
To prevent users from running new pipelines for fork projects in the parent project
use the projects API to disable the ci_allow_fork_pipelines_to_run_in_parent_project
setting.
[!warning] Pipelines created before the setting was disabled are not affected and continue to run. If you rerun a job in an older pipeline, the job uses the same context as when the pipeline was originally created.
When you use merge request pipelines, you can use:
{{< history >}}
{{< /history >}}
You can control access to protected CI/CD variables and protected runners from merge request pipelines.
Merge request pipelines can only access these protected resources when:
Merge request pipelines from forked repositories cannot access these protected resources.
Prerequisites:
To control access to protected variables and runners: