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

45 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!
2020-01-01 13:55:28 +05:30
pipeline.retryable_builds.preload_needs.find_each do |build|
2017-08-17 22:00:37 +05:30
next unless can?(current_user, :update_build, build)
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
2020-01-01 13:55:28 +05:30
# In a DAG, the dependencies may have already completed. Figure out
# which builds have succeeded and use them to update the pipeline. If we don't
# do this, then builds will be stuck in the created state since their dependencies
# will never run.
completed_build_ids = pipeline.find_successful_build_ids_by_names(needs) if needs.any?
2017-08-17 22:00:37 +05:30
pipeline.builds.latest.skipped.find_each do |skipped|
retry_optimistic_lock(skipped) { |build| build.process }
end
MergeRequests::AddTodoWhenBuildFailsService
.new(project, current_user)
.close_all(pipeline)
2020-01-01 13:55:28 +05:30
Ci::ProcessPipelineService
.new(pipeline)
2020-03-09 13:42:32 +05:30
.execute(completed_build_ids, initial_process: true)
2017-08-17 22:00:37 +05:30
end
end
end