Commit dfa8ab6f authored by Markus Doits's avatar Markus Doits

handle old retry format in build (possibly saved in database)

parent 293c7b9e
......@@ -317,12 +317,23 @@ module Ci
pipeline.builds.retried.where(name: self.name).count
end
# The format of the retry option changed in GitLab 11.5. Before it was an
# integer only, after it is a hash. New builds always created have the
# correct format, but builds created before GitLab 11.5 and saved in
# database still have the old integer only format. This helper method makes
# sure that the format is always correct when accessing the retry options,
# even on old builds.
def sanitized_retry_option
value = options&.[](:retry)
value.is_a?(Integer) ? { max: value } : value
end
def retries_max
options&.dig(:retry, :max) || 0
sanitized_retry_option&.[](:max) || 0
end
def retry_when
options&.dig(:retry, :when) || ['always']
sanitized_retry_option&.[](:when) || ['always']
end
def retry_failure?
......
......@@ -1495,6 +1495,14 @@ describe Ci::Build do
expect(subject.retries_max).to eq 0
end
end
context 'with integer only config option' do
subject { create(:ci_build, options: { retry: 1 }) }
it 'returns the number of configured max retries' do
expect(subject.retries_max).to eq 1
end
end
end
describe '#retry_when' do
......@@ -1513,6 +1521,14 @@ describe Ci::Build do
expect(subject.retry_when).to eq ['always']
end
end
context 'with integer only config option' do
subject { create(:ci_build, options: { retry: 1 }) }
it 'returns always array' do
expect(subject.retry_when).to eq ['always']
end
end
end
describe '#retry_failure?' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment