debian-mirror-gitlab/app/services/ci/retry_pipeline_service.rb

59 lines
1.5 KiB
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
module Ci
class RetryPipelineService < ::BaseService
include Gitlab::OptimisticLocking
def execute(pipeline)
2022-05-07 20:08:51 +05:30
access_response = check_access(pipeline)
return access_response if access_response.error?
2017-08-17 22:00:37 +05:30
2020-05-24 23:13:21 +05:30
pipeline.ensure_scheduling_type!
2021-09-30 23:02:18 +05:30
builds_relation(pipeline).find_each do |build|
next unless can_be_retried?(build)
2017-08-17 22:00:37 +05:30
2022-06-21 17:19:12 +05:30
Ci::RetryJobService.new(project, current_user).clone!(build)
2017-08-17 22:00:37 +05:30
end
2021-11-18 22:05:49 +05:30
pipeline.processables.latest.skipped.find_each do |skipped|
2021-04-17 20:07:23 +05:30
retry_optimistic_lock(skipped, name: 'ci_retry_pipeline') { |build| build.process(current_user) }
2017-08-17 22:00:37 +05:30
end
2021-06-08 01:23:25 +05:30
pipeline.reset_source_bridge!(current_user)
2020-11-24 15:15:51 +05:30
2021-04-29 21:17:54 +05:30
::MergeRequests::AddTodoWhenBuildFailsService
2021-06-08 01:23:25 +05:30
.new(project: project, current_user: current_user)
2017-08-17 22:00:37 +05:30
.close_all(pipeline)
2020-01-01 13:55:28 +05:30
Ci::ProcessPipelineService
.new(pipeline)
2020-10-24 23:57:45 +05:30
.execute
2022-05-07 20:08:51 +05:30
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-08-17 22:00:37 +05:30
end
2021-09-30 23:02:18 +05:30
private
def builds_relation(pipeline)
pipeline.retryable_builds.preload_needs
end
def can_be_retried?(build)
can?(current_user, :update_build, build)
end
2017-08-17 22:00:37 +05:30
end
end
2021-09-30 23:02:18 +05:30
Ci::RetryPipelineService.prepend_mod_with('Ci::RetryPipelineService')