Class: Environments::CreateForJobService

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

Overview

This class creates an environment record for a pipeline job.

Instance Method Summary collapse

Methods included from Gitlab::InternalEventsTracking

#track_internal_event

Instance Method Details

#execute(job) ⇒ Object



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

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

  environment = to_resource(job)

  if environment.persisted?
    job.run_after_commit do
      job.link_to_environment(environment)
    end

    job.persisted_environment = environment

    track_environment_usage(job, environment)
  else
    job.assign_attributes(status: :failed, failure_reason: :environment_creation_failure)
  end

  environment
end