Commit 4bf37b54 authored by Fabio Pitino's avatar Fabio Pitino

Merge branch '331703-fix-stuck-multiprojects' into 'master'

Fix stuck bridge jobs when downstream project is invalid

See merge request gitlab-org/gitlab!68365
parents ff3342be 1553ea1b
...@@ -28,10 +28,10 @@ module Ci ...@@ -28,10 +28,10 @@ module Ci
state_machine :status do state_machine :status do
after_transition [:created, :manual, :waiting_for_resource] => :pending do |bridge| after_transition [:created, :manual, :waiting_for_resource] => :pending do |bridge|
next unless bridge.downstream_project next unless bridge.triggers_downstream_pipeline?
bridge.run_after_commit do bridge.run_after_commit do
bridge.schedule_downstream_pipeline! ::Ci::CreateCrossProjectPipelineWorker.perform_async(bridge.id)
end end
end end
...@@ -64,12 +64,6 @@ module Ci ...@@ -64,12 +64,6 @@ module Ci
) )
end end
def schedule_downstream_pipeline!
raise InvalidBridgeTypeError unless downstream_project
::Ci::CreateCrossProjectPipelineWorker.perform_async(self.id)
end
def inherit_status_from_downstream!(pipeline) def inherit_status_from_downstream!(pipeline)
case pipeline.status case pipeline.status
when 'success' when 'success'
...@@ -112,10 +106,18 @@ module Ci ...@@ -112,10 +106,18 @@ module Ci
pipeline if triggers_child_pipeline? pipeline if triggers_child_pipeline?
end end
def triggers_downstream_pipeline?
triggers_child_pipeline? || triggers_cross_project_pipeline?
end
def triggers_child_pipeline? def triggers_child_pipeline?
yaml_for_downstream.present? yaml_for_downstream.present?
end end
def triggers_cross_project_pipeline?
downstream_project_path.present?
end
def tags def tags
[:bridge] [:bridge]
end end
......
...@@ -42,9 +42,9 @@ RSpec.describe Ci::Bridge do ...@@ -42,9 +42,9 @@ RSpec.describe Ci::Bridge do
end end
it 'does not schedule downstream pipeline creation' do it 'does not schedule downstream pipeline creation' do
expect(bridge).not_to receive(:schedule_downstream_pipeline!)
bridge.enqueue! bridge.enqueue!
expect(::Ci::CreateCrossProjectPipelineWorker.jobs).to be_empty
end end
end end
end end
......
...@@ -74,18 +74,18 @@ RSpec.describe Ci::Bridge do ...@@ -74,18 +74,18 @@ RSpec.describe Ci::Bridge do
it "schedules downstream pipeline creation when the status is #{status}" do it "schedules downstream pipeline creation when the status is #{status}" do
bridge.status = status bridge.status = status
expect(bridge).to receive(:schedule_downstream_pipeline!)
bridge.enqueue! bridge.enqueue!
expect(::Ci::CreateCrossProjectPipelineWorker.jobs.last['args']).to eq([bridge.id])
end end
end end
it "schedules downstream pipeline creation when the status is waiting for resource" do it "schedules downstream pipeline creation when the status is waiting for resource" do
bridge.status = :waiting_for_resource bridge.status = :waiting_for_resource
expect(bridge).to receive(:schedule_downstream_pipeline!)
bridge.enqueue_waiting_for_resource! bridge.enqueue_waiting_for_resource!
expect(::Ci::CreateCrossProjectPipelineWorker.jobs.last['args']).to eq([bridge.id])
end end
it 'raises error when the status is failed' do it 'raises error when the status is failed' do
......
...@@ -908,6 +908,39 @@ RSpec.shared_examples 'Pipeline Processing Service' do ...@@ -908,6 +908,39 @@ RSpec.shared_examples 'Pipeline Processing Service' do
end end
end end
context 'when a bridge job has invalid downstream project', :sidekiq_inline do
let(:config) do
<<-EOY
test:
stage: test
script: echo test
deploy:
stage: deploy
trigger:
project: invalid-project
EOY
end
let(:pipeline) do
Ci::CreatePipelineService.new(project, user, { ref: 'master' }).execute(:push).payload
end
before do
stub_ci_pipeline_yaml_file(config)
end
it 'creates a pipeline, then fails the bridge job' do
expect(all_builds_names).to contain_exactly('test', 'deploy')
expect(all_builds_statuses).to contain_exactly('pending', 'created')
succeed_pending
expect(all_builds_names).to contain_exactly('test', 'deploy')
expect(all_builds_statuses).to contain_exactly('success', 'failed')
end
end
private private
def all_builds def all_builds
......
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