Commit 9a5af789 authored by Matija Čupić's avatar Matija Čupić

Fail upstream bridge on pipeline creation failure

Fails the upstream bridge when the downstream pipeline errors out during
creation.
parent 09dc78fd
...@@ -15,7 +15,8 @@ module EE ...@@ -15,7 +15,8 @@ module EE
invalid_bridge_trigger: 1_003, invalid_bridge_trigger: 1_003,
upstream_bridge_project_not_found: 1_004, upstream_bridge_project_not_found: 1_004,
insufficient_upstream_permissions: 1_005, insufficient_upstream_permissions: 1_005,
bridge_pipeline_is_child_pipeline: 1_006) bridge_pipeline_is_child_pipeline: 1_006,
downstream_bridge_pipeline_creation_failed: 1_007)
end end
end end
end end
......
...@@ -11,7 +11,8 @@ module EE ...@@ -11,7 +11,8 @@ module EE
downstream_bridge_project_not_found: 'This job could not be executed because downstream bridge project could not be found.', downstream_bridge_project_not_found: 'This job could not be executed because downstream bridge project could not be found.',
upstream_bridge_project_not_found: 'This job could not be executed because upstream bridge project could not be found.', upstream_bridge_project_not_found: 'This job could not be executed because upstream bridge project could not be found.',
invalid_bridge_trigger: 'This job could not be executed because downstream pipeline trigger definition is invalid.', invalid_bridge_trigger: 'This job could not be executed because downstream pipeline trigger definition is invalid.',
bridge_pipeline_is_child_pipeline: 'This job belongs to a child pipeline and cannot create further child pipelines.' bridge_pipeline_is_child_pipeline: 'This job belongs to a child pipeline and cannot create further child pipelines.',
downstream_bridge_pipeline_creation_failed: 'The downstream project pipeline could not be created.'
).freeze ).freeze
EE::CommitStatusPresenter.private_constant :EE_CALLOUT_FAILURE_MESSAGES EE::CommitStatusPresenter.private_constant :EE_CALLOUT_FAILURE_MESSAGES
......
...@@ -18,7 +18,7 @@ module Ci ...@@ -18,7 +18,7 @@ module Ci
current_user, current_user,
pipeline_params.fetch(:target_revision)) pipeline_params.fetch(:target_revision))
service.execute( downstream_pipeline = service.execute(
pipeline_params.fetch(:source), pipeline_params[:execute_params]) do |pipeline| pipeline_params.fetch(:source), pipeline_params[:execute_params]) do |pipeline|
@bridge.sourced_pipelines.build( @bridge.sourced_pipelines.build(
source_pipeline: @bridge.pipeline, source_pipeline: @bridge.pipeline,
...@@ -28,6 +28,10 @@ module Ci ...@@ -28,6 +28,10 @@ module Ci
pipeline.variables.build(@bridge.downstream_variables) pipeline.variables.build(@bridge.downstream_variables)
end end
downstream_pipeline.tap do |pipeline|
@bridge.drop!(:downstream_bridge_pipeline_creation_failed) if pipeline.has_yaml_errors?
end
end end
private private
......
...@@ -16,7 +16,8 @@ module EE ...@@ -16,7 +16,8 @@ module EE
upstream_bridge_project_not_found: 'upstream project could not be found', upstream_bridge_project_not_found: 'upstream project could not be found',
insufficient_bridge_permissions: 'no permissions to trigger downstream pipeline', insufficient_bridge_permissions: 'no permissions to trigger downstream pipeline',
insufficient_upstream_permissions: 'no permissions to read upstream project', insufficient_upstream_permissions: 'no permissions to read upstream project',
bridge_pipeline_is_child_pipeline: 'creation of child pipeline not allowed from another child pipeline' bridge_pipeline_is_child_pipeline: 'creation of child pipeline not allowed from another child pipeline',
downstream_bridge_pipeline_creation_failed: 'downstream bridge pipeline can not be created'
).freeze ).freeze
EE::Gitlab::Ci::Status::Build::Failed.private_constant :EE_REASONS EE::Gitlab::Ci::Status::Build::Failed.private_constant :EE_REASONS
end end
......
...@@ -241,6 +241,33 @@ describe Ci::CreateCrossProjectPipelineService, '#execute' do ...@@ -241,6 +241,33 @@ describe Ci::CreateCrossProjectPipelineService, '#execute' do
end end
end end
context 'when downstream pipeline creation errors out' do
let(:stub_config) { false }
before do
stub_ci_pipeline_yaml_file(YAML.dump(invalid: { yaml: 'error' }))
end
it 'creates only one new pipeline' do
expect { service.execute(bridge) }
.to change { Ci::Pipeline.count }.by(1)
end
it 'creates a new pipeline in the downstream project' do
pipeline = service.execute(bridge)
expect(pipeline.user).to eq bridge.user
expect(pipeline.project).to eq downstream_project
end
it 'drops the bridge' do
pipeline = service.execute(bridge)
expect(pipeline.reload).to be_failed
expect(bridge.reload).to be_failed
end
end
context 'when bridge job has YAML variables defined' do context 'when bridge job has YAML variables defined' do
before do before do
bridge.yaml_variables = [{ key: 'BRIDGE', value: 'var', public: true }] bridge.yaml_variables = [{ key: 'BRIDGE', value: 'var', public: true }]
......
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