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
|
|
|
|
description tag_list].freeze
|
|
|
|
|
|
|
|
REJECT_ACCESSORS = %i[id status user token coverage trace runner
|
|
|
|
artifacts_expire_at artifacts_file
|
|
|
|
artifacts_metadata artifacts_size
|
|
|
|
created_at updated_at started_at finished_at
|
|
|
|
queued_at erased_by erased_at].freeze
|
|
|
|
|
|
|
|
IGNORE_ACCESSORS = %i[type lock_version target_url gl_project_id
|
|
|
|
deploy job_id base_tags commit_id deployments
|
|
|
|
erased_by_id last_deployment project_id runner_id
|
|
|
|
tag_taggings taggings tags trigger_request_id
|
|
|
|
user_id].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
|