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)
|
|
|
|
unless can?(current_user, :update_pipeline, pipeline)
|
2017-02-13 09:14:40 -05:00
|
|
|
raise Gitlab::Access::AccessDeniedError
|
|
|
|
end
|
|
|
|
|
2019-12-06 13:07:44 -05:00
|
|
|
needs = Set.new
|
|
|
|
|
|
|
|
pipeline.retryable_builds.preload_needs.find_each do |build|
|
2017-05-05 13:35:32 -04:00
|
|
|
next unless can?(current_user, :update_build, build)
|
|
|
|
|
2017-02-23 05:44:49 -05:00
|
|
|
Ci::RetryBuildService.new(project, current_user)
|
2017-04-16 07:14:39 -04:00
|
|
|
.reprocess!(build)
|
2019-12-06 13:07:44 -05:00
|
|
|
|
|
|
|
needs += build.needs.map(&:name)
|
2017-02-23 05:44:49 -05:00
|
|
|
end
|
2017-02-22 03:06:58 -05:00
|
|
|
|
2019-12-06 13:07:44 -05:00
|
|
|
# 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-03-27 03:11:29 -04:00
|
|
|
pipeline.builds.latest.skipped.find_each do |skipped|
|
2017-02-23 05:44:49 -05:00
|
|
|
retry_optimistic_lock(skipped) { |build| build.process }
|
2017-02-14 06:20:02 -05:00
|
|
|
end
|
|
|
|
|
2017-02-15 05:02:05 -05:00
|
|
|
MergeRequests::AddTodoWhenBuildFailsService
|
|
|
|
.new(project, current_user)
|
|
|
|
.close_all(pipeline)
|
|
|
|
|
2019-11-19 07:06:00 -05:00
|
|
|
Ci::ProcessPipelineService
|
|
|
|
.new(pipeline)
|
2020-02-14 07:09:03 -05:00
|
|
|
.execute(completed_build_ids, initial_process: true)
|
2017-02-13 10:38:08 -05:00
|
|
|
end
|
2017-02-13 09:14:40 -05:00
|
|
|
end
|
|
|
|
end
|