summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzegorz@gitlab.com>2018-03-20 16:27:23 +0000
committerGrzegorz Bizon <grzegorz@gitlab.com>2018-03-20 16:27:23 +0000
commita2d82d4c5522b6d3668481e2fcfc77b0830ce9b6 (patch)
tree1dbd697794019471ed95ce417bc64ec01e4c64f7
parent500132e026923cae2a8b769ff1824a00e45bb98c (diff)
parent9c9c0484f61d6c8198c060c78fcfc9458c16955f (diff)
downloadgitlab-ce-a2d82d4c5522b6d3668481e2fcfc77b0830ce9b6.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 e68c1012199..1e066b69c6e 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 9da3de7a828..30a352fd090 100644
--- a/spec/models/ci/build_spec.rb
+++ b/spec/models/ci/build_spec.rb
@@ -2101,6 +2101,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