retry_pipeline_service.rb 776 Bytes
Newer Older
1 2
# frozen_string_literal: true

3
module Ci
4
  class RetryPipelineService < ::BaseService
5 6
    include Gitlab::OptimisticLocking

7 8
    def execute(pipeline)
      unless can?(current_user, :update_pipeline, pipeline)
9 10 11
        raise Gitlab::Access::AccessDeniedError
      end

12
      pipeline.retryable_builds.find_each do |build|
13 14
        next unless can?(current_user, :update_build, build)

15
        Ci::RetryBuildService.new(project, current_user)
16
          .reprocess!(build)
17
      end
18

19
      pipeline.builds.latest.skipped.find_each do |skipped|
20
        retry_optimistic_lock(skipped) { |build| build.process }
21 22
      end

23 24 25 26
      MergeRequests::AddTodoWhenBuildFailsService
        .new(project, current_user)
        .close_all(pipeline)

27
      pipeline.process!
28
    end
29 30
  end
end