2017-02-13 14:14:40 +00:00
|
|
|
module Ci
|
2017-02-14 09:38:17 +00:00
|
|
|
class RetryPipelineService < ::BaseService
|
|
|
|
def execute(pipeline)
|
|
|
|
unless can?(current_user, :update_pipeline, pipeline)
|
2017-02-13 14:14:40 +00:00
|
|
|
raise Gitlab::Access::AccessDeniedError
|
|
|
|
end
|
|
|
|
|
2017-02-22 08:06:58 +00:00
|
|
|
pipeline.builds.failed_or_canceled.tap do |builds|
|
|
|
|
stage_idx = builds.order('stage_idx ASC')
|
|
|
|
.pluck('DISTINCT stage_idx').first
|
2017-02-14 10:38:19 +00:00
|
|
|
|
2017-02-22 08:06:58 +00:00
|
|
|
pipeline.mark_as_processable_after_stage(stage_idx)
|
2017-02-22 07:39:50 +00:00
|
|
|
|
2017-02-22 08:06:58 +00:00
|
|
|
builds.find_each do |build|
|
|
|
|
next unless build.retryable?
|
|
|
|
|
|
|
|
Ci::RetryBuildService.new(project, current_user)
|
|
|
|
.reprocess(build)
|
|
|
|
end
|
2017-02-14 11:20:02 +00:00
|
|
|
end
|
|
|
|
|
2017-02-15 10:02:05 +00:00
|
|
|
MergeRequests::AddTodoWhenBuildFailsService
|
|
|
|
.new(project, current_user)
|
|
|
|
.close_all(pipeline)
|
|
|
|
|
2017-02-14 12:29:58 +00:00
|
|
|
pipeline.process!
|
2017-02-13 15:38:08 +00:00
|
|
|
end
|
2017-02-13 14:14:40 +00:00
|
|
|
end
|
|
|
|
end
|