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

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

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