2017-02-10 09:43:15 -05:00
|
|
|
module Ci
|
2017-02-14 04:38:17 -05:00
|
|
|
class RetryBuildService < ::BaseService
|
2017-03-01 05:39:36 -05: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 16:14:12 -05:00
|
|
|
description tag_list].freeze
|
2017-02-16 07:13:10 -05:00
|
|
|
|
2017-02-14 04:38:17 -05:00
|
|
|
def execute(build)
|
2017-02-14 07:39:14 -05:00
|
|
|
reprocess(build).tap do |new_build|
|
2017-02-14 07:51:12 -05:00
|
|
|
build.pipeline.mark_as_processable_after_stage(build.stage_idx)
|
|
|
|
|
2017-02-14 07:39:14 -05:00
|
|
|
new_build.enqueue!
|
2017-02-14 06:20:02 -05:00
|
|
|
|
2017-02-14 04:38:17 -05:00
|
|
|
MergeRequests::AddTodoWhenBuildFailsService
|
2017-02-15 05:02:05 -05:00
|
|
|
.new(project, current_user)
|
2017-02-14 04:38:17 -05:00
|
|
|
.close(new_build)
|
|
|
|
end
|
2017-02-10 09:43:15 -05:00
|
|
|
end
|
|
|
|
|
2017-02-14 04:38:17 -05:00
|
|
|
def reprocess(build)
|
|
|
|
unless can?(current_user, :update_build, build)
|
2017-02-13 10:38:08 -05:00
|
|
|
raise Gitlab::Access::AccessDeniedError
|
|
|
|
end
|
2017-02-10 09:43:15 -05:00
|
|
|
|
2017-03-01 05:39:36 -05:00
|
|
|
attributes = CLONE_ACCESSORS.map do |attribute|
|
2017-02-16 07:13:10 -05:00
|
|
|
[attribute, build.send(attribute)]
|
|
|
|
end
|
|
|
|
|
|
|
|
attributes.push([:user, current_user])
|
|
|
|
|
|
|
|
project.builds.create(Hash[attributes])
|
2017-02-10 09:43:15 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|