Merge train is skipped when initial pipeline is waiting for manual action
Summary
If
- merge trains are enabled, and if
- the option that requires previous pipelines having succeeded before merging is disabled, and if
- there's a pipeline that has not started and is waiting for manual action
then
- the button that is shown only displays "Merge", and
- clicking it results in merge trains being completely skipped, which
- merges the merge request without any checks
Similar to this: #300663 (closed) and already explained in a comment there #300663 (comment 1027413125)
Steps to reproduce
- Create a blank project
- Add the attached gitlab-ci.yml to the root of the repo.
- Enable merge result pipelines and merge result trains in the settings.
- Create a branch and add a new file to it.
- Create a merge request from that branch to main.
This now created the manual pipeline and I can see the normal Merge button on the MR here and clicking it skips the merge train entirely
What is the current bug behavior?
Merge request is merged without going through a merge train
What is the expected correct behavior?
Clicking the "Merge"-Button (or whatever label it then needs to have) starts a merge train and only if that succeeds the MR is merged.
This bug happens on GitLab.com
Proposal
This is because when evaluating the Merge Request for auto-merge, merge_request.actual_head_pipeline&.complete?
is false https://gitlab.com/gitlab-org/gitlab/-/blob/master/ee/app/services/auto_merge/merge_train_service.rb#L63
Since a "manual" pipeline is not considered a complete one: https://gitlab.com/gitlab-org/gitlab/-/blob/master/app/models/concerns/ci/has_status.rb#L114
The quick fix would be to change the merge_train_service
to run additionally for stuck/manual pipelines, but more investigation is needed to see the ramification of these changes