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

53 lines
1.3 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)
unless can?(current_user, :update_pipeline, pipeline)
raise Gitlab::Access::AccessDeniedError
end
2020-01-01 13:55:28 +05:30
needs = Set.new
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
Ci::RetryBuildService.new(project, current_user)
.reprocess!(build)
2020-01-01 13:55:28 +05:30
needs += build.needs.map(&:name)
2017-08-17 22:00:37 +05:30
end
pipeline.builds.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
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')