Skip to content

Commit c34240d

Browse files
committed
Log errors for failed pipeline creation in PostReceive
When a pipeline fails to create in `PostReceive`, the error is silently discarded, making it difficult to understand why a pipeline was not created. We now add a Sidekiq warning message for this. Adding a Sentry exception when this happens would generate a lot of noise for invalid CI files. Relates to https://gitlab.com/gitlab-org/gitlab-ee/issues/14720
1 parent 1322750 commit c34240d

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed

app/services/git/base_hooks_service.rb

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ def create_pipelines
5757

5858
Ci::CreatePipelineService
5959
.new(project, current_user, pipeline_params)
60-
.execute(:push, pipeline_options)
60+
.execute!(:push, pipeline_options)
61+
rescue Ci::CreatePipelineService::CreateError => ex
62+
log_pipeline_errors(ex)
6163
end
6264

6365
def execute_project_hooks
@@ -125,5 +127,29 @@ def update_remote_mirrors
125127
project.mark_stuck_remote_mirrors_as_failed!
126128
project.update_remote_mirrors
127129
end
130+
131+
def log_pipeline_errors(exception)
132+
data = {
133+
class: self.class.name,
134+
correlation_id: Labkit::Correlation::CorrelationId.current_id.to_s,
135+
project_id: project.id,
136+
project_path: project.full_path,
137+
message: "Error creating pipeline",
138+
errors: exception.to_s,
139+
pipeline_params: pipeline_params
140+
}
141+
142+
logger.warn(data)
143+
end
144+
145+
def logger
146+
if Sidekiq.server?
147+
Sidekiq.logger
148+
else
149+
# This service runs in Sidekiq, so this shouldn't ever be
150+
# called, but this is included just in case.
151+
Gitlab::ProjectServiceLogger
152+
end
153+
end
128154
end
129155
end
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
title: Log errors for failed pipeline creation in PostReceive
3+
merge_request: 32633
4+
author:
5+
type: other

spec/services/git/branch_push_service_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,20 @@
9999
expect(pipeline).to be_push
100100
expect(Gitlab::Git::BRANCH_REF_PREFIX + pipeline.ref).to eq(ref)
101101
end
102+
103+
context 'when pipeline has errors' do
104+
before do
105+
config = YAML.dump({ test: { script: 'ls', only: ['feature'] } })
106+
stub_ci_pipeline_yaml_file(config)
107+
end
108+
109+
it 'reports an error' do
110+
allow(Sidekiq).to receive(:server?).and_return(true)
111+
expect(Sidekiq.logger).to receive(:warn)
112+
113+
expect { subject }.not_to change { Ci::Pipeline.count }
114+
end
115+
end
102116
end
103117

104118
describe "Updates merge requests" do

0 commit comments

Comments
 (0)