Class: Ci::EnsureStageService

Inherits:
BaseService show all
Defined in:
app/services/ci/ensure_stage_service.rb

Overview

We call this service everytime we persist a CI/CD job.

In most cases a job should already have a stage assigned, but in cases it doesn’t have we need to either find existing one or create a brand new stage.

Constant Summary collapse

EnsureStageError =
Class.new(StandardError)

Instance Attribute Summary

Attributes inherited from BaseService

#current_user, #params, #project

Instance Method Summary collapse

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(build) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/services/ci/ensure_stage_service.rb', line 14

def execute(build)
  @build = build

  return if build.stage_id.present?
  return if build.invalid?

  ensure_stage.tap do |stage|
    build.stage_id = stage.id

    yield stage if block_given?
  end
end