2019-09-30 21:07:59 +05:30
---
2020-06-23 00:09:42 +05:30
stage: Verify
group: Continuous Integration
2021-02-22 17:27:13 +05:30
info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/engineering/ux/technical-writing/#assignments
2019-09-30 21:07:59 +05:30
type: reference
last_update: 2019-07-03
---
# Pipelines for Merged Results **(PREMIUM)**
2020-06-23 00:09:42 +05:30
> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/7380) in [GitLab Premium](https://about.gitlab.com/pricing/) 11.10.
2019-09-30 21:07:59 +05:30
2020-04-22 19:07:51 +05:30
When you submit a merge request, you are requesting to merge changes from a
source branch into a target branch. By default, the CI pipeline runs jobs
against the source branch.
2019-09-30 21:07:59 +05:30
2020-04-22 19:07:51 +05:30
With *pipelines for merged results* , the pipeline runs as if the changes from
2021-02-22 17:27:13 +05:30
the source branch have already been merged into the target branch. The commit shown for the pipeline does not exist on the source or target branches but represents the combined target and source branches.
![Merge request widget for merged results pipeline ](img/merged_result_pipeline.png )
2019-09-30 21:07:59 +05:30
2020-04-22 19:07:51 +05:30
If the pipeline fails due to a problem in the target branch, you can wait until the
target is fixed and re-run the pipeline.
2021-02-22 17:27:13 +05:30
This new pipeline runs as if the source is merged with the updated target, and you
don't need to rebase.
2019-09-30 21:07:59 +05:30
2020-04-22 19:07:51 +05:30
The pipeline does not automatically run when the target branch changes. Only changes
to the source branch trigger a new pipeline. If a long time has passed since the last successful
pipeline, you may want to re-run it before merge, to ensure that the source changes
can still be successfully merged into the target.
2019-09-30 21:07:59 +05:30
2020-04-22 19:07:51 +05:30
When the merge request can't be merged, the pipeline runs against the source branch only. For example, when:
2019-09-30 21:07:59 +05:30
2020-04-22 19:07:51 +05:30
- The target branch has changes that conflict with the changes in the source branch.
2020-07-28 23:09:34 +05:30
- The merge request is a [**Draft** merge request ](../../../user/project/merge_requests/work_in_progress_merge_requests.md ).
2019-09-30 21:07:59 +05:30
2020-04-22 19:07:51 +05:30
In these cases, the pipeline runs as a [pipeline for merge requests ](../index.md )
2021-02-22 17:27:13 +05:30
and is labeled as `detached` . If these cases no longer exist, new pipelines
2020-04-22 19:07:51 +05:30
again run against the merged results.
2019-09-30 21:07:59 +05:30
2020-05-24 23:13:21 +05:30
Any user who has developer [permissions ](../../../user/permissions.md ) can run a
pipeline for merged results.
2019-09-30 21:07:59 +05:30
2020-05-24 23:13:21 +05:30
## Prerequisites
2019-09-30 21:07:59 +05:30
2020-05-24 23:13:21 +05:30
To enable pipelines for merge results:
- You must have maintainer [permissions ](../../../user/permissions.md ).
- You must be using [GitLab Runner ](https://gitlab.com/gitlab-org/gitlab-runner ) 11.9 or later.
- You must not be using
2019-09-30 21:07:59 +05:30
[fast forward merges ](../../../user/project/merge_requests/fast_forward_merge.md ) yet.
2020-04-22 19:07:51 +05:30
To follow progress, see [#58226 ](https://gitlab.com/gitlab-org/gitlab/-/issues/26996 ).
2019-09-30 21:07:59 +05:30
2020-04-22 19:07:51 +05:30
## Enable pipelines for merged results
2019-09-30 21:07:59 +05:30
2020-04-22 19:07:51 +05:30
To enable pipelines for merged results for your project:
2019-09-30 21:07:59 +05:30
2020-04-22 19:07:51 +05:30
1. [Configure your CI/CD configuration file ](../index.md#configuring-pipelines-for-merge-requests )
so that the pipeline or individual jobs run for merge requests.
2019-09-30 21:07:59 +05:30
1. Visit your project's **Settings > General** and expand **Merge requests** .
2021-01-29 00:20:46 +05:30
1. Check **Enable merged results pipelines.** .
2020-04-22 19:07:51 +05:30
1. Click **Save changes** .
2021-02-22 17:27:13 +05:30
WARNING:
2020-04-22 19:07:51 +05:30
If you select the check box but don't configure your CI/CD to use
pipelines for merge requests, your merge requests may become stuck in an
unresolved state or your pipelines may be dropped.
2019-09-30 21:07:59 +05:30
2020-04-22 19:07:51 +05:30
## Using Merge Trains
2020-11-24 15:15:51 +05:30
When you enable [Pipelines for merged results ](#pipelines-for-merged-results ),
2020-04-22 19:07:51 +05:30
GitLab [automatically displays ](merge_trains/index.md#add-a-merge-request-to-a-merge-train )
a **Start/Add Merge Train button** .
Generally, this is a safer option than merging merge requests immediately, because your
2021-02-22 17:27:13 +05:30
merge request is evaluated with an expected post-merge result before the actual
2020-04-22 19:07:51 +05:30
merge happens.
2019-09-30 21:07:59 +05:30
2020-04-22 19:07:51 +05:30
For more information, read the [documentation on Merge Trains ](merge_trains/index.md ).
2019-09-30 21:07:59 +05:30
2020-06-23 00:09:42 +05:30
## Automatic pipeline cancellation
2019-12-04 20:38:33 +05:30
2020-06-23 00:09:42 +05:30
> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/12996) in [GitLab Premium](https://about.gitlab.com/pricing/) 12.3.
2019-12-04 20:38:33 +05:30
2021-01-03 14:25:43 +05:30
GitLab CI/CD can detect the presence of redundant pipelines, and cancels them
to conserve CI resources.
2019-12-04 20:38:33 +05:30
When a user merges a merge request immediately within an ongoing merge
2021-02-22 17:27:13 +05:30
train, the train is reconstructed, because it recreates the expected
2019-12-04 20:38:33 +05:30
post-merge commit and pipeline. In this case, the merge train may already
have pipelines running against the previous expected post-merge commit.
2021-02-22 17:27:13 +05:30
These pipelines are considered redundant and are automatically
2019-12-04 20:38:33 +05:30
canceled.
2019-10-12 21:52:04 +05:30
## Troubleshooting
2019-09-30 21:07:59 +05:30
2019-10-12 21:52:04 +05:30
### Pipelines for merged results not created even with new change pushed to merge request
2019-09-30 21:07:59 +05:30
2019-10-12 21:52:04 +05:30
Can be caused by some disabled feature flags. Please make sure that
the following feature flags are enabled on your GitLab instance:
2019-09-30 21:07:59 +05:30
2019-10-12 21:52:04 +05:30
- `:merge_ref_auto_sync`
2019-09-30 21:07:59 +05:30
2020-04-08 14:13:33 +05:30
To check and set these feature flag values, please ask an administrator to:
2019-10-12 21:52:04 +05:30
2020-04-08 14:13:33 +05:30
1. Log into the Rails console of the GitLab instance:
```shell
sudo gitlab-rails console
```
1. Check if the flags are enabled or not:
```ruby
Feature.enabled?(:merge_ref_auto_sync)
```
1. If needed, enable the feature flags:
```ruby
Feature.enable(:merge_ref_auto_sync)
```
2019-10-12 21:52:04 +05:30
2019-12-21 20:55:43 +05:30
### Intermittently pipelines fail by `fatal: reference is not a tree:` error
Since pipelines for merged results are a run on a merge ref of a merge request
2020-01-01 13:55:28 +05:30
(`refs/merge-requests/< iid > /merge`), the Git reference could be overwritten at an
2020-04-08 14:13:33 +05:30
unexpected timing. For example, when a source or target branch is advanced.
2019-12-21 20:55:43 +05:30
In this case, the pipeline fails because of `fatal: reference is not a tree:` error,
which indicates that the checkout-SHA is not found in the merge ref.
2020-11-24 15:15:51 +05:30
This behavior was improved at GitLab 12.4 by introducing [Persistent pipeline refs ](../../troubleshooting.md#fatal-reference-is-not-a-tree-error ).
2019-12-21 20:55:43 +05:30
You should be able to create pipelines at any timings without concerning the error.