summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorKamil Trzcinski <ayufan@ayufan.eu>2016-09-13 14:14:55 +0200
committerKamil Trzcinski <ayufan@ayufan.eu>2016-09-19 10:05:35 +0200
commita4638dddf22797f46d72ea7b73c8453ba68645ab (patch)
tree3b270989070a48e9e1ea3f983070168f863c4bd1 /app
parent1d51bc7dfd04886fa5af69a60bb509691d697813 (diff)
downloadgitlab-ce-a4638dddf22797f46d72ea7b73c8453ba68645ab.tar.gz
Add support for dynamic environments
Environments that can have a URL with predefined CI variables.
Diffstat (limited to 'app')
-rw-r--r--app/models/ci/build.rb4
-rw-r--r--app/models/environment.rb12
-rw-r--r--app/models/merge_request.rb13
-rw-r--r--app/services/create_deployment_service.rb34
4 files changed, 60 insertions, 3 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb
index fb16bc06d71..abdf8c76447 100644
--- a/app/models/ci/build.rb
+++ b/app/models/ci/build.rb
@@ -83,7 +83,9 @@ module Ci
environment: build.environment,
sha: build.sha,
ref: build.ref,
- tag: build.tag)
+ tag: build.tag,
+ options: build.options[:environment],
+ variables: variables)
service.execute(build)
end
end
diff --git a/app/models/environment.rb b/app/models/environment.rb
index 75e6f869786..33c9abf382a 100644
--- a/app/models/environment.rb
+++ b/app/models/environment.rb
@@ -4,6 +4,7 @@ class Environment < ActiveRecord::Base
has_many :deployments
before_validation :nullify_external_url
+ before_save :set_environment_type
validates :name,
presence: true,
@@ -26,6 +27,17 @@ class Environment < ActiveRecord::Base
self.external_url = nil if self.external_url.blank?
end
+ def set_environment_type
+ names = name.split('/')
+
+ self.environment_type =
+ if names.many?
+ names.first
+ else
+ nil
+ end
+ end
+
def includes_commit?(commit)
return false unless last_deployment
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb
index 75f48fd4ba5..b215f02e4b7 100644
--- a/app/models/merge_request.rb
+++ b/app/models/merge_request.rb
@@ -744,10 +744,21 @@ class MergeRequest < ActiveRecord::Base
@pipeline ||= source_project.pipeline_for(source_branch, diff_head_sha)
end
+ def all_commits_sha
+ merge_request_diffs.map(&:commits).flatten.map(&:sha).sort.uniq
+ end
+
+ def latest_pipelines
+ @latest_pipelines ||=
+ if diff_head_sha && source_project
+ source_project.pipelines.order(id: :desc).where(sha: commits_sha, ref: source_branch)
+ end
+ end
+
def all_pipelines
@all_pipelines ||=
if diff_head_sha && source_project
- source_project.pipelines.order(id: :desc).where(sha: commits_sha, ref: source_branch)
+ source_project.pipelines.order(id: :desc).where(sha: all_commits_sha, ref: source_branch)
end
end
diff --git a/app/services/create_deployment_service.rb b/app/services/create_deployment_service.rb
index efeb9df9527..efa0798f47d 100644
--- a/app/services/create_deployment_service.rb
+++ b/app/services/create_deployment_service.rb
@@ -3,9 +3,13 @@ require_relative 'base_service'
class CreateDeploymentService < BaseService
def execute(deployable = nil)
environment = project.environments.find_or_create_by(
- name: params[:environment]
+ name: expanded_name
)
+ if expanded_url
+ environment.external_url = expanded_url
+ end
+
project.deployments.create(
environment: environment,
ref: params[:ref],
@@ -15,4 +19,32 @@ class CreateDeploymentService < BaseService
deployable: deployable
)
end
+
+ private
+
+ def expanded_name
+ name.expand_variables(variables)
+ end
+
+ def expanded_url
+ return unless url
+
+ @expanded_url ||= url.expand_variables(variables)
+ end
+
+ def name
+ params[:environment]
+ end
+
+ def url
+ options[:url]
+ end
+
+ def options
+ params[:environment] || {}
+ end
+
+ def variables
+ params[:variables] || []
+ end
end