diff options
author | Tomasz Maczukin <tomasz@maczukin.pl> | 2018-03-19 14:17:46 +0100 |
---|---|---|
committer | Tomasz Maczukin <tomasz@maczukin.pl> | 2018-03-19 15:26:32 +0100 |
commit | 767e12a25cb3122eec39f9e3ec879cb2b478fe0c (patch) | |
tree | 89540d53eb9a8dd461b61db51f978f458ba93572 | |
parent | ea5221aeb358ef6c349cfa09b9c6993bd7bd027d (diff) | |
download | gitlab-ce-767e12a25cb3122eec39f9e3ec879cb2b478fe0c.tar.gz |
Prevent auto-retry AccessDenied error from stopping transition to failed
-rw-r--r-- | app/models/ci/build.rb | 6 | ||||
-rw-r--r-- | spec/models/ci/build_spec.rb | 28 |
2 files changed, 33 insertions, 1 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index f8a3600e863..4edcfd02157 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/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index 01203ff44c8..79bd1943bff 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -2065,6 +2065,34 @@ 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(Ci::RetryBuildService).to receive(:new).and_return(retry_service) + allow(retry_service).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 + begin + subject.drop! + ensure + expect(subject.failed?).to be_truthy + end + end + end end context 'when build is not configured to be retried' do |