2017-02-10 09:43:15 -05:00
|
|
|
module Ci
|
|
|
|
class RetryBuildService
|
2017-02-10 10:19:29 -05:00
|
|
|
include Gitlab::Allowable
|
|
|
|
|
2017-02-10 09:43:15 -05:00
|
|
|
def initialize(build, user)
|
|
|
|
@build = build
|
|
|
|
@user = user
|
|
|
|
@pipeline = build.pipeline
|
|
|
|
end
|
|
|
|
|
|
|
|
def retry!
|
2017-02-13 10:38:08 -05:00
|
|
|
reprocess!.tap do |new_build|
|
2017-02-10 09:43:15 -05:00
|
|
|
new_build.enqueue!
|
|
|
|
|
|
|
|
MergeRequests::AddTodoWhenBuildFailsService
|
|
|
|
.new(@build.project, @user)
|
|
|
|
.close(new_build)
|
|
|
|
|
|
|
|
@pipeline.mark_as_processable_after_stage(@build.stage_idx)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-02-13 10:38:08 -05:00
|
|
|
def reprocess!
|
|
|
|
unless can?(@user, :update_build, @build)
|
|
|
|
raise Gitlab::Access::AccessDeniedError
|
|
|
|
end
|
2017-02-10 09:43:15 -05:00
|
|
|
|
|
|
|
Ci::Build.create(
|
|
|
|
ref: @build.ref,
|
|
|
|
tag: @build.tag,
|
|
|
|
options: @build.options,
|
|
|
|
commands: @build.commands,
|
|
|
|
tag_list: @build.tag_list,
|
|
|
|
project: @build.project,
|
|
|
|
pipeline: @build.pipeline,
|
|
|
|
name: @build.name,
|
|
|
|
allow_failure: @build.allow_failure,
|
|
|
|
stage: @build.stage,
|
|
|
|
stage_idx: @build.stage_idx,
|
|
|
|
trigger_request: @build.trigger_request,
|
|
|
|
yaml_variables: @build.yaml_variables,
|
|
|
|
when: @build.when,
|
|
|
|
environment: @build.environment,
|
|
|
|
user: @user)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|