Class: Ci::CreateDownstreamPipelineService

Inherits:
BaseService
  • Object
show all
Includes:
DownstreamPipelineHelpers, Gitlab::Utils::StrongMemoize
Defined in:
app/services/ci/create_downstream_pipeline_service.rb

Overview

Takes in input a Ci::Bridge job and creates a downstream pipeline (either multi-project or child pipeline) according to the Ci::Bridge specifications.

Constant Summary collapse

DuplicateDownstreamPipelineError =
Class.new(StandardError)
MAX_NESTED_CHILDREN =
2

Instance Attribute Summary

Attributes inherited from BaseService

#current_user, #params, #project

Instance Method Summary collapse

Methods included from DownstreamPipelineHelpers

#log_downstream_pipeline_creation

Methods inherited from BaseService

#initialize

Methods included from BaseServiceUtility

#deny_visibility_level, #event_service, #log_error, #log_info, #notification_service, #system_hook_service, #todo_service, #visibility_level

Methods included from Gitlab::Allowable

#can?

Constructor Details

This class inherits a constructor from BaseService

Instance Method Details

#execute(bridge) ⇒ Object



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
48
# File 'app/services/ci/create_downstream_pipeline_service.rb', line 15

def execute(bridge)
  @bridge = bridge

  if @bridge.has_downstream_pipeline?
    Gitlab::ErrorTracking.track_exception(
      DuplicateDownstreamPipelineError.new,
      bridge_id: @bridge.id, project_id: @bridge.project_id
    )

    return ServiceResponse.error(message: 'Already has a downstream pipeline')
  end

  pipeline_params = @bridge.downstream_pipeline_params
  target_ref = pipeline_params.dig(:target_revision, :ref)

  return ServiceResponse.error(message: 'Pre-conditions not met') unless ensure_preconditions!(target_ref)

  return ServiceResponse.error(message: 'Can not run the bridge') unless @bridge.run

  service = ::Ci::CreatePipelineService.new(
    pipeline_params.fetch(:project),
    current_user,
    pipeline_params.fetch(:target_revision))

  downstream_pipeline = service
    .execute(pipeline_params.fetch(:source), **pipeline_params[:execute_params])
    .payload

  log_downstream_pipeline_creation(downstream_pipeline)
  update_bridge_status!(@bridge, downstream_pipeline)
rescue StandardError => e
  @bridge.reset.drop!(:data_integrity_failure)
  raise e
end