提交 5f98d059 编写于 作者: K Kamil Trzcinski

Add `action` and `on_stop` to `environment` in .gitlab-ci.yml

上级 6cdbb27e
......@@ -6,14 +6,12 @@ class CreateDeploymentService < BaseService
ActiveRecord::Base.transaction do
@deployable = deployable
@environment = prepare_environment
@environment = environment
@environment.external_url = expanded_url if expanded_url
@environment.state_event = action
@environment.save
if stop?
@environment.stop
return
end
@environment.start
return if @environment.stopped?
deploy.tap do |deployment|
deployment.update_merge_request_metrics!
......@@ -37,10 +35,8 @@ class CreateDeploymentService < BaseService
deployable: @deployable)
end
def prepare_environment
project.environments.find_or_create_by(name: expanded_name) do |environment|
environment.external_url = expanded_url
end
def environment
@environment ||= project.environments.find_or_create_by(name: expanded_name)
end
def expanded_name
......@@ -69,7 +65,7 @@ class CreateDeploymentService < BaseService
params[:variables] || []
end
def stop?
params[:options].fetch(:stop, false)
def action
params[:options].fetch(:action, 'start')
end
end
......@@ -8,7 +8,7 @@ module Gitlab
class Environment < Entry
include Validatable
ALLOWED_KEYS = %i[name url close]
ALLOWED_KEYS = %i[name url action on_stop]
validations do
validate do
......@@ -36,7 +36,11 @@ module Gitlab
addressable_url: true,
allow_nil: true
validates :close, boolean: true, allow_nil: true
validates :action,
inclusion: { in: %w[start stop], message: 'should be start or stop, ' },
allow_nil: true
validates :on_stop, string: true, allow_nil: true
end
end
......@@ -56,9 +60,13 @@ module Gitlab
value[:url]
end
def action
value[:action] || 'start'
end
def value
case @config
when String then { name: @config }
when String then { name: @config, action: 'start' }
when Hash then @config
else {}
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册