summaryrefslogtreecommitdiff
path: root/lib
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 /lib
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 'lib')
-rw-r--r--lib/expand_variables.rb15
-rw-r--r--lib/gitlab/ci/config/node/environment.rb33
-rw-r--r--lib/gitlab/regex.rb4
3 files changed, 50 insertions, 2 deletions
diff --git a/lib/expand_variables.rb b/lib/expand_variables.rb
new file mode 100644
index 00000000000..40bf9483eb5
--- /dev/null
+++ b/lib/expand_variables.rb
@@ -0,0 +1,15 @@
+String.instance_eval
+ def expand_variables(variables)
+ # Convert hash array to variables
+ if variables.is_a?(Array)
+ variables = variables.reduce({}) do |hash, variable|
+ hash[variable[:key]] = variable[:value]
+ hash
+ end
+ end
+
+ self.gsub(/\$([a-zA-Z_][a-zA-Z0-9_]*)|\${\g<1>}|%\g<1>%/) do
+ variables[$1 || $2]
+ end
+ end
+end
diff --git a/lib/gitlab/ci/config/node/environment.rb b/lib/gitlab/ci/config/node/environment.rb
new file mode 100644
index 00000000000..6f04180039e
--- /dev/null
+++ b/lib/gitlab/ci/config/node/environment.rb
@@ -0,0 +1,33 @@
+module Gitlab
+ module Ci
+ class Config
+ module Node
+ ##
+ # Entry that represents environment variables.
+ #
+ class Environment < Entry
+ include Validatable
+
+ validations do
+ include LegacyValidationHelpers
+
+ validate do
+ unless string_or_array_of_strings?(config)
+ errors.add(:config,
+ 'should be a string or an array of strings')
+ end
+ end
+
+ def string_or_array_of_strings?(field)
+ validate_string(field) || validate_array_of_strings(field)
+ end
+ end
+
+ def value
+ Array(@config)
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/regex.rb b/lib/gitlab/regex.rb
index ffad5e17c78..d1a3e54ccd7 100644
--- a/lib/gitlab/regex.rb
+++ b/lib/gitlab/regex.rb
@@ -96,11 +96,11 @@ module Gitlab
end
def environment_name_regex
- @environment_name_regex ||= /\A[a-zA-Z0-9_-]+\z/.freeze
+ git_reference_regex
end
def environment_name_regex_message
- "can contain only letters, digits, '-' and '_'."
+ "be a valid git reference name"
end
end
end