Class: Deployments::CreateForJobService

Inherits:
Object
  • Object
show all
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

Instance Method Details

#execute(job) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/services/deployments/create_for_job_service.rb', line 8

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!
  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