Allow "pipeline must succeed" to merge if the pipeline was empty
Release notes
Sometimes you want to use the only allow merge requests to be merged if the pipeline succeeds feature, but can't because your CI/CD pipeline doesn't run for all changes. For example, you might have a pipeline that runs every time you change code, but doesn't run when you only change README.md
files. Previously, if you enabled this feature, you wouldn't be able to merge those readme changes because no pipeline ran.
Now, there is a setting available that lets you prevent merging with failed pipelines but allows merging when your merge request didn't need a pipeline to run.
Problem to solve
A merge request cannot be merged under the following conditions:
-
Pipeline must succeed
is enable in project settings - Changes in the MR are such that CI config evaluates to all jobs being skipped, so no pipeline manifests. For example, using
job:rules
orworkflow:rules
- Absence of a pipeline fails the condition that "pipeline must succeed" to allow merge according to the project settings
Proposal
NOTE: This proposal depends on a new preparing
state to be added to MergeRequest#merge_status
state machine in issue !54900 (merged).
- Introduce a project setting
require_pipeline_presence
(defaulttrue
) - Allow the project setting to be changed via API
- We might need to ensure that a MR is in
preparing
state any time a merge request pipeline is being created. - Change
MergeRequest#mergeable_ci_state?
to take in consideration the project setting.
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb
index 5fad876d3fb..005940d0894 100644
--- a/app/models/merge_request.rb
+++ b/app/models/merge_request.rb
@@ -1296,7 +1296,9 @@ def can_be_merged_via_command_line_by?(user)
end
def mergeable_ci_state?
+ return false if preparing?
return true unless project.only_allow_merge_if_pipeline_succeeds?
+ return true unless project.require_pipeline_presence?
return false unless actual_head_pipeline
return true if project.allow_merge_on_skipped_pipeline? && actual_head_pipeline.skipped?
The UI components will be completed in issue #300471 (closed).
Intended users
- Delaney (Development Team Lead)
- Sasha (Software Developer)
- Devon (DevOps Engineer)
- Rachel (Release Manager)
User experience goal
Further details
Permissions and Security
Permissions required to perform the described:
- Project Owner
- Project Maintainer
Documentation
Availability & Testing
- Unit tests is required for the new project setting
require_pipeline_presence
implementations - Integration test (feature test) is required to ensure:
- Merge request cannot be merged when
require_pipeline_presence
is true and the pipeline is skipped - Merge request can be merged when
require_pipeline_presence
is true and the pipeline presence but is empty - Merge request can be merged when
require_pipeline_presence
is true and the pipeline succeeds - Merge request can be merged when
require_pipeline_presence
is false and the pipeline is skipped
- Merge request cannot be merged when
- End-to-end test not required.