2017-02-13 14:14:40 +00:00
|
|
|
module Ci
|
2017-02-14 09:38:17 +00:00
|
|
|
class RetryPipelineService < ::BaseService
|
|
|
|
def execute(pipeline)
|
2017-02-13 14:14:40 +00:00
|
|
|
@pipeline = pipeline
|
|
|
|
|
2017-02-14 09:38:17 +00:00
|
|
|
unless can?(current_user, :update_pipeline, pipeline)
|
2017-02-13 14:14:40 +00:00
|
|
|
raise Gitlab::Access::AccessDeniedError
|
|
|
|
end
|
|
|
|
|
2017-02-13 15:38:08 +00:00
|
|
|
##
|
2017-02-14 09:38:17 +00:00
|
|
|
# Reprocess builds in subsequent stages
|
2017-02-13 15:38:08 +00:00
|
|
|
#
|
2017-02-14 09:38:17 +00:00
|
|
|
pipeline.builds
|
2017-02-14 10:38:19 +00:00
|
|
|
.after_stage(resume_stage.index)
|
2017-02-13 15:38:08 +00:00
|
|
|
.failed_or_canceled.find_each do |build|
|
2017-02-14 09:38:17 +00:00
|
|
|
Ci::RetryBuildService
|
|
|
|
.new(project, current_user)
|
|
|
|
.reprocess(build)
|
2017-02-13 14:14:40 +00:00
|
|
|
end
|
2017-02-13 15:38:08 +00:00
|
|
|
|
2017-02-14 10:38:19 +00:00
|
|
|
##
|
|
|
|
# Mark skipped builds as processable again
|
|
|
|
#
|
|
|
|
pipeline.mark_as_processable_after_stage(resume_stage.index)
|
|
|
|
|
2017-02-13 15:38:08 +00:00
|
|
|
##
|
|
|
|
# Retry builds in the first unsuccessful stage
|
|
|
|
#
|
|
|
|
resume_stage.builds.failed_or_canceled.find_each do |build|
|
2017-02-14 09:38:17 +00:00
|
|
|
Ci::RetryBuildService
|
|
|
|
.new(project, current_user)
|
|
|
|
.retry(build)
|
2017-02-13 15:38:08 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def resume_stage
|
|
|
|
@resume_stage ||= @pipeline.stages.find do |stage|
|
|
|
|
stage.failed? || stage.canceled?
|
2017-02-13 14:14:40 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|