diff options
author | Shinya Maeda <shinya@gitlab.com> | 2018-11-27 16:25:42 +0900 |
---|---|---|
committer | Shinya Maeda <shinya@gitlab.com> | 2018-11-27 16:25:42 +0900 |
commit | 96d20ce914458f86e68b57bc1bb88ab8d27f010b (patch) | |
tree | 3ec71a6ae050f919ade472fd3bf633d2a6a83538 | |
parent | 97842068b6cf1432cd400ead749843946b4f51ee (diff) | |
download | gitlab-ce-ignore-failed-pipeline-creation-on-pipeline-schedule.tar.gz |
Print pipeline errorignore-failed-pipeline-creation-on-pipeline-schedule
-rw-r--r-- | app/workers/pipeline_schedule_worker.rb | 6 | ||||
-rw-r--r-- | spec/workers/pipeline_schedule_worker_spec.rb | 40 |
2 files changed, 38 insertions, 8 deletions
diff --git a/app/workers/pipeline_schedule_worker.rb b/app/workers/pipeline_schedule_worker.rb index a98bc51372c..98c6cbaf7f0 100644 --- a/app/workers/pipeline_schedule_worker.rb +++ b/app/workers/pipeline_schedule_worker.rb @@ -4,7 +4,7 @@ class PipelineScheduleWorker include ApplicationWorker include CronjobQueue - InsufficientPermissionError = Class.new(StandardError) + FailedToCreatePipelineError = Class.new(StandardError) # rubocop: disable CodeReuse/ActiveRecord def perform @@ -16,7 +16,9 @@ class PipelineScheduleWorker ref: schedule.ref) .execute(:schedule, ignore_skip_ci: true, save_on_errors: true, schedule: schedule) - raise InsufficientPermissionError, 'Failed to create pipeline' unless pipeline.persisted? + unless pipeline.persisted? + error(schedule, FailedToCreatePipelineError.new(pipeline.errors.full_messages.join(','))) + end rescue => e error(schedule, e) ensure diff --git a/spec/workers/pipeline_schedule_worker_spec.rb b/spec/workers/pipeline_schedule_worker_spec.rb index fa7e3070740..3acf1d66699 100644 --- a/spec/workers/pipeline_schedule_worker_spec.rb +++ b/spec/workers/pipeline_schedule_worker_spec.rb @@ -68,13 +68,33 @@ describe PipelineScheduleWorker do expect(Ci::Pipeline.last.yaml_errors).not_to be_nil end end - end - context 'when the schedule is not runnable by the user' do - it 'raises InsufficientPermissionError' do - expect { subject }.to raise_error(PipelineScheduleWorker::InsufficientPermissionError) + context 'when gitlab-ci.yml is missing' do + before do + allow(Gitlab::Sentry).to receive(:track_exception) + stub_ci_pipeline_yaml_file(nil) + end + + it 'logging a pipeline error' do + expect(Rails.logger) + .to receive(:error) + .with(a_string_matching("Missing .gitlab-ci.yml file")) + .and_call_original + + subject + end + + it 'does not create a pipeline' do + expect { subject }.not_to change { project.pipelines.count } + end + + it 'does not raise an exception' do + expect { subject }.not_to raise_error + end end + end + context 'when the schedule is not runnable by the user' do context 'when it is executed in production environment' do before do allow(Gitlab::Sentry).to receive(:track_exception) @@ -92,9 +112,13 @@ describe PipelineScheduleWorker do .with(:pipeline_schedule_creation_failed_total, "Counter of failed attempts of pipeline schedule creation") .and_call_original + subject + end + + it 'logging a pipeline error' do expect(Rails.logger) .to receive(:error) - .with(a_string_matching("Failed to create a scheduled pipeline")) + .with(a_string_matching("Insufficient permissions to create a new pipeline")) .and_call_original subject @@ -103,6 +127,10 @@ describe PipelineScheduleWorker do it 'does not create a pipeline' do expect { subject }.not_to change { project.pipelines.count } end + + it 'does not raise an exception' do + expect { subject }.not_to raise_error + end end end @@ -111,7 +139,7 @@ describe PipelineScheduleWorker do allow(Ci::CreatePipelineService).to receive(:new).and_raise(ArgumentError) end - it 'does not raise error and report to Sentry' do + it 'does not raise error and report to Sentry' do expect(Gitlab::Sentry) .to receive(:track_exception) .with(ArgumentError, |