summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzegorz@gitlab.com>2018-03-20 16:27:23 +0000
committerMayra Cabrera <mcabrera@gitlab.com>2018-03-23 10:25:25 -0600
commit9ceaad7a1034a4878513ca202f6953822cffd395 (patch)
treedbc850ec2d23d90c22d960b1dec0884ade5d1e9b
parent33c35a15f1610a58f9f1bcaeb313ed99583dd085 (diff)
downloadgitlab-ce-9ceaad7a1034a4878513ca202f6953822cffd395.tar.gz
Merge branch 'fix-ci-job-auto-retry' into 'master'
Prevent auto-retry AccessDenied error from stopping transition to failed See merge request gitlab-org/gitlab-ce!17862
-rw-r--r--app/models/ci/build.rb6
-rw-r--r--changelogs/unreleased/fix-ci-job-auto-retry.yml5
-rw-r--r--spec/models/ci/build_spec.rb29
3 files changed, 39 insertions, 1 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb
index 62e59dc2e8f..ae24758112a 100644
--- a/app/models/ci/build.rb
+++ b/app/models/ci/build.rb
@@ -140,7 +140,11 @@ module Ci
next if build.retries_max.zero?
if build.retries_count < build.retries_max
- Ci::Build.retry(build, build.user)
+ begin
+ Ci::Build.retry(build, build.user)
+ rescue Gitlab::Access::AccessDeniedError => ex
+ Rails.logger.error "Unable to auto-retry job #{build.id}: #{ex}"
+ end
end
end
diff --git a/changelogs/unreleased/fix-ci-job-auto-retry.yml b/changelogs/unreleased/fix-ci-job-auto-retry.yml
new file mode 100644
index 00000000000..442126461f0
--- /dev/null
+++ b/changelogs/unreleased/fix-ci-job-auto-retry.yml
@@ -0,0 +1,5 @@
+---
+title: Prevent auto-retry AccessDenied error from stopping transition to failed
+merge_request: 17862
+author:
+type: fixed
diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb
index 59b82bfa093..b40749298d8 100644
--- a/spec/models/ci/build_spec.rb
+++ b/spec/models/ci/build_spec.rb
@@ -2050,6 +2050,35 @@ describe Ci::Build do
subject.drop!
end
+
+ context 'when retry service raises Gitlab::Access::AccessDeniedError exception' do
+ let(:retry_service) { Ci::RetryBuildService.new(subject.project, subject.user) }
+
+ before do
+ allow_any_instance_of(Ci::RetryBuildService)
+ .to receive(:execute)
+ .with(subject)
+ .and_raise(Gitlab::Access::AccessDeniedError)
+ allow(Rails.logger).to receive(:error)
+ end
+
+ it 'handles raised exception' do
+ expect { subject.drop! }.not_to raise_exception(Gitlab::Access::AccessDeniedError)
+ end
+
+ it 'logs the error' do
+ subject.drop!
+
+ expect(Rails.logger)
+ .to have_received(:error)
+ .with(a_string_matching("Unable to auto-retry job #{subject.id}"))
+ end
+
+ it 'fails the job' do
+ subject.drop!
+ expect(subject.failed?).to be_truthy
+ end
+ end
end
context 'when build is not configured to be retried' do