2017-02-10 14:43:15 +00:00
|
|
|
module Ci
|
2017-02-14 09:38:17 +00:00
|
|
|
class RetryBuildService < ::BaseService
|
2017-02-16 12:13:10 +00:00
|
|
|
CLONE_ATTRIBUTES = %i[pipeline ref tag options commands tag_list name
|
|
|
|
allow_failure stage stage_idx trigger_request
|
|
|
|
yaml_variables when environment coverage_regex]
|
|
|
|
.freeze
|
|
|
|
|
|
|
|
REJECT_ATTRIBUTES = %i[id status user token coverage trace runner
|
|
|
|
artifacts_file artifacts_metadata artifacts_size
|
|
|
|
created_at updated_at started_at finished_at
|
|
|
|
queued_at erased_by erased_at].freeze
|
|
|
|
|
|
|
|
IGNORE_ATTRIBUTES = %i[trace type lock_version project target_url
|
|
|
|
deploy job_id description].freeze
|
|
|
|
|
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-02-16 12:13:10 +00:00
|
|
|
attributes = CLONE_ATTRIBUTES.map do |attribute|
|
|
|
|
[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
|