Commit 043a8dd7 authored by Jan Provaznik's avatar Jan Provaznik

Merge branch 'mc/bug/fail-upstream-on-invalid-yaml' into 'master'

Fail upstream bridge on pipeline creation failure

Closes #198354

See merge request gitlab-org/gitlab!24092
parents 6fd55c2c 8fc82cbd
---
title: Fail upstream bridge on downstream pipeline creation failure.
merge_request: 24092
author:
type: fixed
......@@ -15,7 +15,8 @@ module EE
invalid_bridge_trigger: 1_003,
upstream_bridge_project_not_found: 1_004,
insufficient_upstream_permissions: 1_005,
bridge_pipeline_is_child_pipeline: 1_006)
bridge_pipeline_is_child_pipeline: 1_006,
downstream_pipeline_creation_failed: 1_007)
end
end
end
......
......@@ -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.',
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.',
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_pipeline_creation_failed: 'The downstream pipeline could not be created.'
).freeze
EE::CommitStatusPresenter.private_constant :EE_CALLOUT_FAILURE_MESSAGES
......
......@@ -18,7 +18,7 @@ module Ci
current_user,
pipeline_params.fetch(:target_revision))
service.execute(
downstream_pipeline = service.execute(
pipeline_params.fetch(:source), pipeline_params[:execute_params]) do |pipeline|
@bridge.sourced_pipelines.build(
source_pipeline: @bridge.pipeline,
......@@ -28,6 +28,10 @@ module Ci
pipeline.variables.build(@bridge.downstream_variables)
end
downstream_pipeline.tap do |pipeline|
@bridge.drop!(:downstream_pipeline_creation_failed) if pipeline.has_yaml_errors?
end
end
private
......
......@@ -16,7 +16,8 @@ module EE
upstream_bridge_project_not_found: 'upstream project could not be found',
insufficient_bridge_permissions: 'no permissions to trigger downstream pipeline',
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_pipeline_creation_failed: 'downstream pipeline can not be created'
).freeze
EE::Gitlab::Ci::Status::Build::Failed.private_constant :EE_REASONS
end
......
......@@ -241,6 +241,34 @@ describe Ci::CreateCrossProjectPipelineService, '#execute' do
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
expect(bridge.failure_reason).to eq('downstream_pipeline_creation_failed')
end
end
context 'when bridge job has YAML variables defined' do
before do
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