stage | group | info | type |
---|---|---|---|
Create |
Code Review |
To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/product/ux/technical-writing/#assignments |
reference, concepts |
Merge when pipeline succeeds and Add to merge train when pipeline succeeds renamed to Auto-merge in GitLab 16.0 with a flag named
auto_merge_labels_mr_widget
. Enabled by default.
If you review a merge request and it's ready to merge, but the pipeline hasn't completed yet, you can set it to auto-merge. You don't have to remember later to merge the work manually:
NOTE: In GitLab 16.0 and later, Merge when pipeline succeeds and Add to merge train when pipeline succeeds are renamed Set to auto-merge.
If the pipeline succeeds, the merge request is merged. If the pipeline fails, the author can either retry any failed jobs, or push new commits to fix the failure:
- If a retried job succeeds on the second try, the merge request is merged.
- If new commits are added to the merge request, GitLab cancels the request to ensure the new changes are reviewed before merge.
Prerequisites:
- You must have at least the Developer role in the project.
- If the project is configured to require it, all threads in the merge request must be resolved.
- The merge request must have received all required approvals.
To do this when pushing from the command line, use the merge_request.merge_when_pipeline_succeeds
push option.
To do this from the GitLab user interface:
- On the left sidebar, at the top, select Search GitLab ({search}) to find your project.
- Select Code > Merge requests.
- Select the merge request to edit.
- Scroll to the merge request reports section.
- Optional. Select your desired merge options, such as Delete source branch, Squash commits, or Edit commit message.
- Select Auto-merge.
If a new comment is added to the merge request after you select Auto-merge, but before the pipeline completes, GitLab blocks the merge until you resolve all existing threads.
If a merge request is set to auto-merge, you can cancel it.
Prerequisites:
- You must either be the author of the merge request, or a project member with at least the Developer role.
- The merge request's pipeline must still be in progress.
To do this:
- On the left sidebar, at the top, select Search GitLab ({search}) to find your project.
- Select Code > Merge requests.
- Select the merge request to edit.
- Scroll to the merge request reports section.
- Select Cancel auto-merge.
You can configure your project to require a complete and successful pipeline before merge. This configuration works for both:
- GitLab CI/CD pipelines.
- Pipelines run from an external CI integration.
As a result, disabling GitLab CI/CD pipelines does not disable this feature, but you can use pipelines from external CI providers with it.
Prerequisites:
- Ensure CI/CD is configured to run a pipeline for every merge request.
- You must have at least the Maintainer role in the project.
To enable this setting:
- On the left sidebar, at the top, select Search GitLab ({search}) to find your project.
- Select Settings > Merge requests.
- Scroll to Merge checks, and select Pipelines must succeed. This setting also prevents merge requests from being merged if there is no pipeline, which can conflict with some rules.
- Select Save.
Introduced in GitLab 13.1.
When the Pipelines must succeed checkbox is checked, skipped pipelines prevent merge requests from being merged.
Prerequisite:
- You must have at least the Maintainer role in the project.
To change this behavior:
- On the left sidebar, at the top, select Search GitLab ({search}) to find your project.
- Select Settings > Merge requests.
- Under Merge checks:
- Select Pipelines must succeed.
- Select Skipped pipelines are considered successful.
- Select Save.
If you require a successful pipeline for a merge, this setting can conflict with some
use cases that do not generate pipelines, such as only/except
or rules
. Ensure your project
runs a pipeline for
every merge request, and that the pipeline is successful.
If a merge request triggers both a branch pipeline and a merge request pipeline, the success or failure of only the merge request pipeline is checked. If the merge request pipeline contains fewer jobs than the branch pipeline, it could allow code that fails tests to be merged, like in this example:
branch-pipeline-job:
rules:
- if: $CI_PIPELINE_SOURCE == "push"
script:
- echo "Testing happens here."
merge-request-pipeline-job:
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
script:
- echo "No testing happens here. This pipeline always succeeds, and enables merge."
- echo true
Instead, use branch (push
) pipelines or merge request pipelines, when possible.
For details on avoiding two pipelines for a single merge request, read the
rules
documentation.
When the Pipelines must succeed setting is combined with the Merged results pipelines feature, failed branch pipeline may be ignored. Issue 385841 is open to track this.