summaryrefslogtreecommitdiff
path: root/app/services/ci/retry_build_service.rb
blob: b7a9a55dd9e1dcbaa72e6ee9636e45d8d0e9d5ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
module Ci
  class RetryBuildService
    include Gitlab::Allowable

    def initialize(build, user)
      @build = build
      @user = user
      @pipeline = build.pipeline
    end

    def retry!
      reprocess!.tap do |new_build|
        new_build.enqueue!

        MergeRequests::AddTodoWhenBuildFailsService
          .new(@build.project, @user)
          .close(new_build)

        @pipeline.mark_as_processable_after_stage(@build.stage_idx)
      end
    end

    def reprocess!
      unless can?(@user, :update_build, @build)
        raise Gitlab::Access::AccessDeniedError
      end

      Ci::Build.create(
        ref: @build.ref,
        tag: @build.tag,
        options: @build.options,
        commands: @build.commands,
        tag_list: @build.tag_list,
        project: @build.project,
        pipeline: @build.pipeline,
        name: @build.name,
        allow_failure: @build.allow_failure,
        stage: @build.stage,
        stage_idx: @build.stage_idx,
        trigger_request: @build.trigger_request,
        yaml_variables: @build.yaml_variables,
        when: @build.when,
        environment: @build.environment,
        user: @user)
    end
  end
end