Commit 10def378 authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch 'mc/bug/persist-downstream-subscription-resilient' into 'master'

Pass upstream bridge to pipeline creation service

See merge request gitlab-org/gitlab!25625
parents da1153ee 4b480158
...@@ -167,7 +167,10 @@ module Ci ...@@ -167,7 +167,10 @@ module Ci
target_revision: { target_revision: {
ref: target_ref || downstream_project.default_branch ref: target_ref || downstream_project.default_branch
}, },
execute_params: { ignore_skip_ci: true } execute_params: {
ignore_skip_ci: true,
bridge: self
}
} }
end end
......
...@@ -20,12 +20,6 @@ module Ci ...@@ -20,12 +20,6 @@ module Ci
service.execute( 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(
source_pipeline: @bridge.pipeline,
source_project: @bridge.project,
project: @bridge.downstream_project,
pipeline: pipeline)
pipeline.variables.build(@bridge.downstream_variables) pipeline.variables.build(@bridge.downstream_variables)
end end
end end
......
...@@ -7,6 +7,7 @@ module Ci ...@@ -7,6 +7,7 @@ module Ci
CreateError = Class.new(StandardError) CreateError = Class.new(StandardError)
SEQUENCE = [Gitlab::Ci::Pipeline::Chain::Build, SEQUENCE = [Gitlab::Ci::Pipeline::Chain::Build,
Gitlab::Ci::Pipeline::Chain::Build::Associations,
Gitlab::Ci::Pipeline::Chain::Validate::Abilities, Gitlab::Ci::Pipeline::Chain::Validate::Abilities,
Gitlab::Ci::Pipeline::Chain::Validate::Repository, Gitlab::Ci::Pipeline::Chain::Validate::Repository,
Gitlab::Ci::Pipeline::Chain::Config::Content, Gitlab::Ci::Pipeline::Chain::Config::Content,
......
# frozen_string_literal: true
module Gitlab
module Ci
module Pipeline
module Chain
class Build
class Associations < Chain::Base
def perform!
return unless @command.bridge
@pipeline.build_source_pipeline(
source_pipeline: @command.bridge.pipeline,
source_project: @command.bridge.project,
source_bridge: @command.bridge,
project: @command.project
)
end
def break?
false
end
end
end
end
end
end
end
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::Ci::Pipeline::Chain::Build::Associations do
let(:project) { create(:project, :repository) }
let(:user) { create(:user, developer_projects: [project]) }
let(:pipeline) { Ci::Pipeline.new }
let(:step) { described_class.new(pipeline, command) }
let(:command) do
Gitlab::Ci::Pipeline::Chain::Command.new(
source: :push,
origin_ref: 'master',
checkout_sha: project.commit.id,
after_sha: nil,
before_sha: nil,
trigger_request: nil,
schedule: nil,
merge_request: nil,
project: project,
current_user: user,
bridge: bridge)
end
context 'when a bridge is passed in to the pipeline creation' do
let(:bridge) { create(:ci_bridge) }
it 'links the pipeline to the upstream bridge job' do
step.perform!
expect(pipeline.source_pipeline).to be_present
expect(pipeline.source_pipeline).to be_valid
expect(pipeline.source_pipeline).to have_attributes(
source_pipeline: bridge.pipeline, source_project: bridge.project,
source_bridge: bridge, project: project
)
end
it 'never breaks the chain' do
step.perform!
expect(step.break?).to eq(false)
end
end
context 'when a bridge is not passed in to the pipeline creation' do
let(:bridge) { nil }
it 'leaves the source pipeline empty' do
step.perform!
expect(pipeline.source_pipeline).to be_nil
end
it 'never breaks the chain' do
step.perform!
expect(step.break?).to eq(false)
end
end
end
...@@ -109,7 +109,7 @@ describe Ci::CreateCrossProjectPipelineService, '#execute' do ...@@ -109,7 +109,7 @@ describe Ci::CreateCrossProjectPipelineService, '#execute' do
expect(pipeline.source_bridge).to be_a ::Ci::Bridge expect(pipeline.source_bridge).to be_a ::Ci::Bridge
end end
it 'updates bridge status when downstream pipeline gets proceesed' do it 'updates bridge status when downstream pipeline gets processed' do
pipeline = service.execute(bridge) pipeline = service.execute(bridge)
expect(pipeline.reload).to be_pending expect(pipeline.reload).to be_pending
...@@ -128,6 +128,37 @@ describe Ci::CreateCrossProjectPipelineService, '#execute' do ...@@ -128,6 +128,37 @@ describe Ci::CreateCrossProjectPipelineService, '#execute' do
end end
end end
context 'when downstream pipeline has yaml configuration error' do
before do
stub_ci_pipeline_yaml_file(YAML.dump(job: { invalid: 'yaml' }))
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 a downstream project' do
pipeline = service.execute(bridge)
expect(pipeline.user).to eq bridge.user
expect(pipeline.project).to eq downstream_project
expect(bridge.sourced_pipelines.first.pipeline).to eq pipeline
expect(pipeline.triggered_by_pipeline).to eq upstream_pipeline
expect(pipeline.source_bridge).to eq bridge
expect(pipeline.source_bridge).to be_a ::Ci::Bridge
end
it 'does not update bridge status when downstream pipeline gets processed' do
pipeline = service.execute(bridge)
expect(pipeline.reload).to be_failed
# TODO: This should change to failed once #198354 gets fixed.
# https://gitlab.com/gitlab-org/gitlab/-/merge_requests/25706
expect(bridge.reload).to be_pending
end
end
context 'when downstream project is the same as the job project' do context 'when downstream project is the same as the job project' do
let(:trigger) do let(:trigger) do
{ trigger: { project: upstream_project.full_path } } { trigger: { project: upstream_project.full_path } }
...@@ -173,7 +204,7 @@ describe Ci::CreateCrossProjectPipelineService, '#execute' do ...@@ -173,7 +204,7 @@ describe Ci::CreateCrossProjectPipelineService, '#execute' do
expect(pipeline.source_bridge).to be_a ::Ci::Bridge expect(pipeline.source_bridge).to be_a ::Ci::Bridge
end end
it 'updates bridge status when downstream pipeline gets proceesed' do it 'updates bridge status when downstream pipeline gets processed' do
pipeline = service.execute(bridge) pipeline = service.execute(bridge)
expect(pipeline.reload).to be_pending expect(pipeline.reload).to be_pending
......
...@@ -4,18 +4,22 @@ require 'spec_helper' ...@@ -4,18 +4,22 @@ require 'spec_helper'
describe Ci::CreatePipelineService do describe Ci::CreatePipelineService do
let_it_be(:project) { create(:project, :repository) } let_it_be(:project) { create(:project, :repository) }
let_it_be(:user) { create(:admin) } let_it_be(:user) { create(:admin) }
let(:upstream_pipeline) { create(:ci_pipeline) }
let(:ref) { 'refs/heads/master' } let(:ref) { 'refs/heads/master' }
let(:service) { described_class.new(project, user, { ref: ref }) } let(:service) { described_class.new(project, user, { ref: ref }) }
context 'custom config content' do context 'custom config content' do
let(:bridge) do let(:bridge) do
double(:bridge, yaml_for_downstream: <<~YML create(:ci_bridge, status: 'running', pipeline: upstream_pipeline, project: upstream_pipeline.project).tap do |bridge|
rspec: allow(bridge).to receive(:yaml_for_downstream).and_return(
script: rspec <<~YML
custom: rspec:
script: custom script: rspec
YML custom:
) script: custom
YML
)
end
end end
subject { service.execute(:push, bridge: bridge) } subject { service.execute(:push, bridge: bridge) }
......
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