Commit 78775c94 authored by Fabio Pitino's avatar Fabio Pitino

Merge branch 'ab-fix-parent-child-pipeline-cyclical-detection' into 'master'

Fix bug where pipelines were tagged a cyclical inappropriately

See merge request gitlab-org/gitlab!63070
parents 1779781b 7dfb4697
...@@ -19,13 +19,14 @@ module Ci ...@@ -19,13 +19,14 @@ module Ci
DuplicateDownstreamPipelineError.new, DuplicateDownstreamPipelineError.new,
bridge_id: @bridge.id, project_id: @bridge.project_id bridge_id: @bridge.id, project_id: @bridge.project_id
) )
return
return error('Already has a downstream pipeline')
end end
pipeline_params = @bridge.downstream_pipeline_params pipeline_params = @bridge.downstream_pipeline_params
target_ref = pipeline_params.dig(:target_revision, :ref) target_ref = pipeline_params.dig(:target_revision, :ref)
return unless ensure_preconditions!(target_ref) return error('Pre-conditions not met') unless ensure_preconditions!(target_ref)
service = ::Ci::CreatePipelineService.new( service = ::Ci::CreatePipelineService.new(
pipeline_params.fetch(:project), pipeline_params.fetch(:project),
...@@ -119,8 +120,11 @@ module Ci ...@@ -119,8 +120,11 @@ module Ci
return false if @bridge.triggers_child_pipeline? return false if @bridge.triggers_child_pipeline?
if Feature.enabled?(:ci_drop_cyclical_triggered_pipelines, @bridge.project, default_enabled: :yaml) if Feature.enabled?(:ci_drop_cyclical_triggered_pipelines, @bridge.project, default_enabled: :yaml)
checksums = @bridge.pipeline.base_and_ancestors.map { |pipeline| config_checksum(pipeline) } pipeline_checksums = @bridge.pipeline.base_and_ancestors.filter_map do |pipeline|
checksums.uniq.length != checksums.length config_checksum(pipeline) unless pipeline.child?
end
pipeline_checksums.uniq.length != pipeline_checksums.length
end end
end end
......
...@@ -136,7 +136,7 @@ RSpec.describe Ci::CreateDownstreamPipelineService, '#execute' do ...@@ -136,7 +136,7 @@ RSpec.describe Ci::CreateDownstreamPipelineService, '#execute' do
bridge_id: bridge.id, project_id: bridge.project.id) bridge_id: bridge.id, project_id: bridge.project.id)
.and_call_original .and_call_original
expect(Ci::CreatePipelineService).not_to receive(:new) expect(Ci::CreatePipelineService).not_to receive(:new)
expect(service.execute(bridge)).to be_nil expect(service.execute(bridge)).to eq({ message: "Already has a downstream pipeline", status: :error })
end end
end end
...@@ -393,6 +393,51 @@ RSpec.describe Ci::CreateDownstreamPipelineService, '#execute' do ...@@ -393,6 +393,51 @@ RSpec.describe Ci::CreateDownstreamPipelineService, '#execute' do
end end
end end
end end
context 'when multi-project pipeline runs from child pipelines bridge job' do
before do
stub_ci_pipeline_yaml_file(YAML.dump(rspec: { script: 'rspec' }))
end
# instantiate new service, to clear memoized values from child pipeline run
subject(:execute_with_trigger_project_bridge) do
described_class.new(upstream_project, user).execute(trigger_project_bridge)
end
let!(:child_pipeline) do
service.execute(bridge)
bridge.downstream_pipeline
end
let!(:trigger_downstream_project) do
{
trigger: {
project: downstream_project.full_path,
branch: 'feature'
}
}
end
let!(:trigger_project_bridge) do
create(
:ci_bridge, status: :pending,
user: user,
options: trigger_downstream_project,
pipeline: child_pipeline
)
end
it 'creates a new pipeline' do
expect { execute_with_trigger_project_bridge }
.to change { Ci::Pipeline.count }.by(1)
new_pipeline = trigger_project_bridge.downstream_pipeline
expect(new_pipeline.child?).to eq(false)
expect(new_pipeline.triggered_by_pipeline).to eq child_pipeline
expect(trigger_project_bridge.reload).not_to be_failed
end
end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment