add an option when to retry a build (unused yet)

This commit is contained in:
Markus Doits 2018-09-15 13:39:55 +02:00
parent d71a779740
commit 473b52b283
No known key found for this signature in database
GPG key ID: A0796D16BD3D3DAE
2 changed files with 31 additions and 0 deletions

View file

@ -324,6 +324,11 @@ module Ci
retries.is_a?(Hash) && retries.fetch(:max, 0) || retries || 0
end
def retry_when
retries = self.options[:retry]
retries.is_a?(Hash) && retries.fetch(:when, 'always').to_s || 'always'
end
def latest?
!retried?
end

View file

@ -1512,6 +1512,32 @@ describe Ci::Build do
end
end
end
describe '#retry_when' do
context 'when value is defined' do
subject { create(:ci_build, options: { retry: { when: :something } }) }
it 'returns the configured value' do
expect(subject.retry_when).to eq :something
end
end
context 'when value is not defined' do
subject { create(:ci_build) }
it 'returns `always`' do
expect(subject.retry_when).to eq :always
end
end
context 'when retry is only defined as an integer' do
subject { create(:ci_build, options: { retry: 1 }) }
it 'returns `always`' do
expect(subject.retry_when).to eq :always
end
end
end
end
describe '#keep_artifacts!' do