diff options
Diffstat (limited to 'app/models/ci/build.rb')
-rw-r--r-- | app/models/ci/build.rb | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index 432f3f242eb..416a2a33378 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -96,6 +96,14 @@ module Ci BuildSuccessWorker.perform_async(id) end end + + before_transition any => [:failed] do |build| + next if build.retries_max.zero? + + if build.retries_count < build.retries_max + Ci::Build.retry(build, build.user) + end + end end def detailed_status(current_user) @@ -130,6 +138,14 @@ module Ci success? || failed? || canceled? end + def retries_count + pipeline.builds.retried.where(name: self.name).count + end + + def retries_max + self.options.fetch(:retry, 0).to_i + end + def latest? !retried? end |