Merge request pipelines doesn't work with parent-child pipeline flow
Problem
Merge request pipelines doesn't work with parent-child pipeline flow. When user creates a pipeline, pipelines in MR context are going to be stuck as running status. This can be reproduced in this demo project https://gitlab.com/dosuken123/parent-child-pipelines/merge_requests/2, https://gitlab.com/dosuken123/parent-child-pipelines/merge_requests/3.
The problem is that a child pipeline doesn't have merge_request association so that it raises an exception at a permission check (For more details, please take a look at the following sentry log). We can resolve this by passing merge_request object to child pipeline.
Sentry
Title: NoMethodError: undefined method `source_branch' for nil:NilClass
https://sentry.gitlab.net/gitlab/gitlabcom/issues/1194517/
NoMethodError: undefined method `source_branch' for nil:NilClass
gitlab/ci/pipeline/chain/validate/abilities.rb:44:in `allowed_to_write_ref?'
access.can_update_branch?(@command.merge_request.source_branch)
gitlab/ci/pipeline/chain/validate/abilities.rb:21:in `perform!'
unless allowed_to_write_ref?
ee/gitlab/ci/pipeline/chain/validate/abilities.rb:21:in `perform!'
super
gitlab/ci/pipeline/chain/sequence.rb:19:in `block in build!'
step.perform!
gitlab/ci/pipeline/chain/sequence.rb:16:in `each'
@sequence.each do |chain|
...
(64 additional frame(s) were not displayed)
undefined method `source_branch' for nil:NilClass
Edited by Shinya Maeda