deployable.rb 827 Bytes
Newer Older
1 2 3 4 5 6 7 8 9
# frozen_string_literal: true

module Deployable
  extend ActiveSupport::Concern

  included do
    after_create :create_deployment

    def create_deployment
10
      return unless starts_environment? && !has_deployment?
11 12 13 14 15

      environment = project.environments.find_or_create_by(
        name: expanded_environment_name
      )

16 17 18 19
      # If we failed to persist envirionment record by validation error, such as name with invalid character,
      # the job will fall back to a non-environment job.
      return unless environment.persisted?

Kamil Trzciński's avatar
Kamil Trzciński committed
20
      create_deployment!(
21
        cluster_id: environment.deployment_platform&.cluster_id,
22 23 24 25 26 27
        project_id: environment.project_id,
        environment: environment,
        ref: ref,
        tag: tag,
        sha: sha,
        user: user,
28
        on_stop: on_stop)
29 30 31
    end
  end
end