Fix merge request pipelines on ambiguous refs
What does this MR do and why?
When the merge request source branch was ambiguous in the source project, detached merge request pipelines would pick commit SHA associated with the tag instead of the merge request's branch.
We fix that by using source_branch_ref
instead of source_branch
in
the places deciding the commit used by detached merge request pipelines.
We ran into this in one of our projects on GitLab.com, see this slack thread (internal link) and the affected MR
MR acceptance checklist
Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Screenshots or screen recordings
Screenshots are required for UI changes, and strongly recommended for all other merge requests.
Before | After |
---|---|
How to set up and validate locally
- Add a
.gitlab-ci.yml
with the contentworkflow: rules: - if: $CI_PIPELINE_SOURCE == 'merge_request_event' && $CI_MERGE_REQUEST_EVENT_TYPE == 'detached' - if: $CI_COMMIT_TAG - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
- Create a tag and branch with the same name
- Create a merge request from the branch
- Run a pipeline
Expected results: The pipeline should have the same commit SHA as the source branch. Without these changes, it uses the tag's commit SHA.