Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Trzcinski <ayufan@ayufan.eu>2016-10-17 13:46:00 +0300
committerKamil Trzcinski <ayufan@ayufan.eu>2016-10-17 13:46:00 +0300
commit5f98d059396dc8c0faab4defd0414049c909b6c1 (patch)
treed6e3f2935d89d6bae212d3f4f307fe83e941f7f7
parent6cdbb27ec3cf72ce6728986909aa3df54b7a26c6 (diff)
Add `action` and `on_stop` to `environment` in .gitlab-ci.yml
-rw-r--r--app/services/create_deployment_service.rb22
-rw-r--r--lib/gitlab/ci/config/node/environment.rb14
2 files changed, 20 insertions, 16 deletions
diff --git a/app/services/create_deployment_service.rb b/app/services/create_deployment_service.rb
index 47c740addb0..2e859a30cac 100644
--- a/app/services/create_deployment_service.rb
+++ b/app/services/create_deployment_service.rb
@@ -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
diff --git a/lib/gitlab/ci/config/node/environment.rb b/lib/gitlab/ci/config/node/environment.rb
index daa115f9017..1c1d07843b1 100644
--- a/lib/gitlab/ci/config/node/environment.rb
+++ b/lib/gitlab/ci/config/node/environment.rb
@@ -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