Class: Deployments::CreateForJobService

Inherits:
Object
  • Object
show all
Includes:
Gitlab::InternalEventsTracking
Defined in:
app/services/deployments/create_for_job_service.rb

Overview

This class creates a deployment record for a pipeline job.

Constant Summary collapse

DeploymentCreationError =
Class.new(StandardError)

Instance Method Summary collapse

Methods included from Gitlab::InternalEventsTracking

#track_internal_event

Instance Method Details

#execute(job) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/services/deployments/create_for_job_service.rb', line 10

def execute(job)
  return unless job.is_a?(::Ci::Processable) && job.persisted_environment.present?

  environment = job.actual_persisted_environment

  deployment = to_resource(job, environment)

  return unless deployment

  deployment.save!

  if Feature.enabled?(:persisted_job_environment_relationship, job.project) && job.job_environment.present?
    job.job_environment.update!(deployment: deployment)
  end

  job.association(:deployment).target = deployment
  job.association(:deployment).loaded!

  deployment
rescue ActiveRecord::RecordInvalid => e
  Gitlab::ErrorTracking.track_and_raise_for_dev_exception(
    DeploymentCreationError.new(e.message), job_id: job.id)
end