2018-07-16 12:31:01 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-02-13 09:14:40 -05:00
|
|
|
module Ci
|
2017-02-14 04:38:17 -05:00
|
|
|
class RetryPipelineService < ::BaseService
|
2017-02-23 05:44:49 -05:00
|
|
|
include Gitlab::OptimisticLocking
|
|
|
|
|
2017-02-14 04:38:17 -05:00
|
|
|
def execute(pipeline)
|
2022-03-14 08:07:59 -04:00
|
|
|
access_response = check_access(pipeline)
|
|
|
|
return access_response if access_response.error?
|
2017-02-13 09:14:40 -05:00
|
|
|
|
2020-05-15 11:08:04 -04:00
|
|
|
pipeline.ensure_scheduling_type!
|
|
|
|
|
2021-06-18 14:10:13 -04:00
|
|
|
builds_relation(pipeline).find_each do |build|
|
|
|
|
next unless can_be_retried?(build)
|
2017-05-05 13:35:32 -04:00
|
|
|
|
2022-03-23 14:08:47 -04:00
|
|
|
Ci::RetryJobService.new(project, current_user).clone!(build)
|
2017-02-23 05:44:49 -05:00
|
|
|
end
|
2017-02-22 03:06:58 -05:00
|
|
|
|
2021-10-13 14:12:40 -04:00
|
|
|
pipeline.processables.latest.skipped.find_each do |skipped|
|
2021-03-02 10:10:57 -05:00
|
|
|
retry_optimistic_lock(skipped, name: 'ci_retry_pipeline') { |build| build.process(current_user) }
|
2017-02-14 06:20:02 -05:00
|
|
|
end
|
|
|
|
|
2021-04-30 14:10:09 -04:00
|
|
|
pipeline.reset_source_bridge!(current_user)
|
2020-09-17 08:09:37 -04:00
|
|
|
|
2021-04-01 17:09:22 -04:00
|
|
|
::MergeRequests::AddTodoWhenBuildFailsService
|
2021-05-11 23:10:21 -04:00
|
|
|
.new(project: project, current_user: current_user)
|
2017-02-15 05:02:05 -05:00
|
|
|
.close_all(pipeline)
|
|
|
|
|
2019-11-19 07:06:00 -05:00
|
|
|
Ci::ProcessPipelineService
|
|
|
|
.new(pipeline)
|
2020-08-13 11:10:03 -04:00
|
|
|
.execute
|
2022-03-14 08:07:59 -04:00
|
|
|
|
|
|
|
ServiceResponse.success
|
|
|
|
rescue Gitlab::Access::AccessDeniedError => e
|
|
|
|
ServiceResponse.error(message: e.message, http_status: :forbidden)
|
|
|
|
end
|
|
|
|
|
|
|
|
def check_access(pipeline)
|
|
|
|
if can?(current_user, :update_pipeline, pipeline)
|
|
|
|
ServiceResponse.success
|
|
|
|
else
|
|
|
|
ServiceResponse.error(message: '403 Forbidden', http_status: :forbidden)
|
|
|
|
end
|
2017-02-13 10:38:08 -05:00
|
|
|
end
|
2021-06-18 14:10:13 -04:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def builds_relation(pipeline)
|
|
|
|
pipeline.retryable_builds.preload_needs
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_be_retried?(build)
|
|
|
|
can?(current_user, :update_build, build)
|
|
|
|
end
|
2017-02-13 09:14:40 -05:00
|
|
|
end
|
|
|
|
end
|
2021-06-18 14:10:13 -04:00
|
|
|
|
|
|
|
Ci::RetryPipelineService.prepend_mod_with('Ci::RetryPipelineService')
|