diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-06-22 12:22:53 +0300 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-06-22 12:22:53 +0300 |
commit | 05ce8a118743a5d896b6b8cc99b40af214ac8cd1 (patch) | |
tree | 8ddad8e7a7c75c274404c62d3ed583ad1a0c0b71 /lib | |
parent | 04ecfca386b70800d3876d3f11ff7451e95d9087 (diff) |
Handle CI environment variables in a new CI config
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ci/gitlab_ci_yaml_processor.rb | 6 | ||||
-rw-r--r-- | lib/gitlab/ci/config.rb | 3 | ||||
-rw-r--r-- | lib/gitlab/ci/config/node/global.rb | 3 | ||||
-rw-r--r-- | lib/gitlab/ci/config/node/validators.rb | 10 | ||||
-rw-r--r-- | lib/gitlab/ci/config/node/variables.rb | 22 |
5 files changed, 38 insertions, 6 deletions
diff --git a/lib/ci/gitlab_ci_yaml_processor.rb b/lib/ci/gitlab_ci_yaml_processor.rb index c0f2a258836..436b0127c3d 100644 --- a/lib/ci/gitlab_ci_yaml_processor.rb +++ b/lib/ci/gitlab_ci_yaml_processor.rb @@ -67,9 +67,9 @@ module Ci @image = @ci_config.image @after_script = @ci_config.after_script @services = @ci_config.services + @variables = @ci_config.variables @stages = @config[:stages] || @config[:types] - @variables = @config[:variables] || {} @cache = @config[:cache] @jobs = {} @@ -126,10 +126,6 @@ module Ci raise ValidationError, "stages should be an array of strings" end - unless @variables.nil? || validate_variables(@variables) - raise ValidationError, "variables should be a map of key-value strings" - end - validate_global_cache! if @cache end diff --git a/lib/gitlab/ci/config.rb b/lib/gitlab/ci/config.rb index 8475e47d2b0..1bea9c21f6a 100644 --- a/lib/gitlab/ci/config.rb +++ b/lib/gitlab/ci/config.rb @@ -7,7 +7,8 @@ module Gitlab ## # Temporary delegations that should be removed after refactoring # - delegate :before_script, :image, :services, :after_script, to: :@global + delegate :before_script, :image, :services, :after_script, :variables, + to: :@global def initialize(config) @config = Loader.new(config).load! diff --git a/lib/gitlab/ci/config/node/global.rb b/lib/gitlab/ci/config/node/global.rb index 7b8d6d63a08..3bb6f98ed0f 100644 --- a/lib/gitlab/ci/config/node/global.rb +++ b/lib/gitlab/ci/config/node/global.rb @@ -20,6 +20,9 @@ module Gitlab allow_node :after_script, Script, description: 'Script that will be executed after each job.' + + allow_node :variables, Variables, + description: 'Environment variables that will be used.' end end end diff --git a/lib/gitlab/ci/config/node/validators.rb b/lib/gitlab/ci/config/node/validators.rb index a76f041c953..56f7661daf0 100644 --- a/lib/gitlab/ci/config/node/validators.rb +++ b/lib/gitlab/ci/config/node/validators.rb @@ -23,6 +23,16 @@ module Gitlab end end end + + class VariablesValidator < ActiveModel::EachValidator + include LegacyValidationHelpers + + def validate_each(record, attribute, value) + unless validate_variables(value) + record.errors.add(attribute, 'should be a hash of key value pairs') + end + end + end end end end diff --git a/lib/gitlab/ci/config/node/variables.rb b/lib/gitlab/ci/config/node/variables.rb new file mode 100644 index 00000000000..5decd777bdb --- /dev/null +++ b/lib/gitlab/ci/config/node/variables.rb @@ -0,0 +1,22 @@ +module Gitlab + module Ci + class Config + module Node + ## + # Entry that represents environment variables. + # + class Variables < Entry + include Validatable + + validations do + validates :value, variables: true + end + + def value + @config || {} + end + end + end + end + end +end |