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
state_machine :status do
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.schedule_downstream_pipeline!
::Ci::CreateCrossProjectPipelineWorker.perform_async(bridge.id)
end
end
......@@ -64,12 +64,6 @@ module Ci
)
end
def schedule_downstream_pipeline!
raise InvalidBridgeTypeError unless downstream_project
::Ci::CreateCrossProjectPipelineWorker.perform_async(self.id)
end
def inherit_status_from_downstream!(pipeline)
case pipeline.status
when 'success'
......@@ -112,10 +106,18 @@ module Ci
pipeline if triggers_child_pipeline?
end
def triggers_downstream_pipeline?
triggers_child_pipeline? || triggers_cross_project_pipeline?
end
def triggers_child_pipeline?
yaml_for_downstream.present?
end
def triggers_cross_project_pipeline?
downstream_project_path.present?
end
def tags
[:bridge]
end
......
......@@ -42,9 +42,9 @@ RSpec.describe Ci::Bridge do
end
it 'does not schedule downstream pipeline creation' do
expect(bridge).not_to receive(:schedule_downstream_pipeline!)
bridge.enqueue!
expect(::Ci::CreateCrossProjectPipelineWorker.jobs).to be_empty
end
end
end
......
......@@ -74,18 +74,18 @@ RSpec.describe Ci::Bridge do
it "schedules downstream pipeline creation when the status is #{status}" do
bridge.status = status
expect(bridge).to receive(:schedule_downstream_pipeline!)
bridge.enqueue!
expect(::Ci::CreateCrossProjectPipelineWorker.jobs.last['args']).to eq([bridge.id])
end
end
it "schedules downstream pipeline creation when the status is waiting for resource" do
bridge.status = :waiting_for_resource
expect(bridge).to receive(:schedule_downstream_pipeline!)
bridge.enqueue_waiting_for_resource!
expect(::Ci::CreateCrossProjectPipelineWorker.jobs.last['args']).to eq([bridge.id])
end
it 'raises error when the status is failed' do
......
......@@ -908,6 +908,39 @@ RSpec.shared_examples 'Pipeline Processing Service' do
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
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