summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarkus Doits <markus.doits@stellenticket.de>2018-10-24 22:22:10 +0200
committerMarkus Doits <markus.doits@stellenticket.de>2018-11-07 13:05:22 +0100
commitdfa8ab6f4219774104412c76b76c2716c44ccf3c (patch)
tree1b08ce7fc91ed32356810aac2fdbe1ce5ce30f21
parent293c7b9e4164a2b224d6fcf80c402757130cff1f (diff)
downloadgitlab-ce-dfa8ab6f4219774104412c76b76c2716c44ccf3c.tar.gz
handle old retry format in build (possibly saved in database)
-rw-r--r--app/models/ci/build.rb15
-rw-r--r--spec/models/ci/build_spec.rb16
2 files changed, 29 insertions, 2 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb
index 7b220487495..bebf356d1bf 100644
--- a/app/models/ci/build.rb
+++ b/app/models/ci/build.rb
@@ -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?
diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb
index 8a7b06ad21c..6849bc6db7a 100644
--- a/spec/models/ci/build_spec.rb
+++ b/spec/models/ci/build_spec.rb
@@ -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