2017-02-10 14:43:15 +00:00
|
|
|
module Ci
|
2017-02-14 09:38:17 +00:00
|
|
|
class RetryBuildService < ::BaseService
|
2017-03-01 10:39:36 +00:00
|
|
|
CLONE_ACCESSORS = %i[pipeline project ref tag options commands name
|
|
|
|
allow_failure stage stage_idx trigger_request
|
|
|
|
yaml_variables when environment coverage_regex
|
2017-03-02 21:14:12 +00:00
|
|
|
description tag_list].freeze
|
2017-02-16 12:13:10 +00:00
|
|
|
|
2017-02-14 09:38:17 +00:00
|
|
|
def execute(build)
|
2017-02-14 12:39:14 +00:00
|
|
|
reprocess(build).tap do |new_build|
|
2017-02-14 12:51:12 +00:00
|
|
|
build.pipeline.mark_as_processable_after_stage(build.stage_idx)
|
|
|
|
|
2017-02-14 12:39:14 +00:00
|
|
|
new_build.enqueue!
|
2017-02-14 11:20:02 +00:00
|
|
|
|
2017-02-14 09:38:17 +00:00
|
|
|
MergeRequests::AddTodoWhenBuildFailsService
|
2017-02-15 10:02:05 +00:00
|
|
|
.new(project, current_user)
|
2017-02-14 09:38:17 +00:00
|
|
|
.close(new_build)
|
|
|
|
end
|
2017-02-10 14:43:15 +00:00
|
|
|
end
|
|
|
|
|
2017-02-14 09:38:17 +00:00
|
|
|
def reprocess(build)
|
|
|
|
unless can?(current_user, :update_build, build)
|
2017-02-13 15:38:08 +00:00
|
|
|
raise Gitlab::Access::AccessDeniedError
|
|
|
|
end
|
2017-02-10 14:43:15 +00:00
|
|
|
|
2017-03-01 10:39:36 +00:00
|
|
|
attributes = CLONE_ACCESSORS.map do |attribute|
|
2017-02-16 12:13:10 +00:00
|
|
|
[attribute, build.send(attribute)]
|
|
|
|
end
|
|
|
|
|
|
|
|
attributes.push([:user, current_user])
|
|
|
|
|
|
|
|
project.builds.create(Hash[attributes])
|
2017-02-10 14:43:15 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|