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
|
2018-01-25 09:15:51 -05:00
|
|
|
allow_failure stage stage_id stage_idx trigger_request
|
2017-03-01 05:39:36 -05:00
|
|
|
yaml_variables when environment coverage_regex
|
2017-08-31 08:13:40 -04:00
|
|
|
description tag_list protected].freeze
|
2017-02-16 07:13:10 -05:00
|
|
|
|
2017-02-14 04:38:17 -05:00
|
|
|
def execute(build)
|
2017-04-16 07:14:39 -04: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-04-16 07:14:39 -04:00
|
|
|
def reprocess!(build)
|
2017-02-14 04:38:17 -05:00
|
|
|
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-08-10 12:39:26 -04:00
|
|
|
[attribute, build.public_send(attribute)] # rubocop:disable GitlabSecurity/PublicSend
|
2017-02-16 07:13:10 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
attributes.push([:user, current_user])
|
|
|
|
|
2017-10-13 11:26:17 -04:00
|
|
|
build.retried = true
|
|
|
|
|
2017-04-16 07:14:39 -04:00
|
|
|
Ci::Build.transaction do
|
|
|
|
# mark all other builds of that name as retried
|
2017-05-09 07:14:45 -04:00
|
|
|
build.pipeline.builds.latest
|
|
|
|
.where(name: build.name)
|
2017-04-16 07:14:39 -04:00
|
|
|
.update_all(retried: true)
|
|
|
|
|
|
|
|
project.builds.create!(Hash[attributes])
|
|
|
|
end
|
2017-02-10 09:43:15 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|