diff --git a/changelogs/unreleased/allow_numeric_values_in_gitlab_ci_yml.yml b/changelogs/unreleased/allow_numeric_values_in_gitlab_ci_yml.yml new file mode 100644 index 0000000000000000000000000000000000000000..8c7fa53a18b89d7c512f04eb28d94ccd585fc415 --- /dev/null +++ b/changelogs/unreleased/allow_numeric_values_in_gitlab_ci_yml.yml @@ -0,0 +1,4 @@ +--- +title: Allow numeric values in gitlab-ci.yml +merge_request: 10607 +author: blackst0ne diff --git a/doc/ci/yaml/README.md b/doc/ci/yaml/README.md index 16308a957cb31036255a0111c45e80be64d085b5..8546a99a0225868aec3c3c92fed35c336a875f8e 100644 --- a/doc/ci/yaml/README.md +++ b/doc/ci/yaml/README.md @@ -147,6 +147,10 @@ variables: DATABASE_URL: "postgres://postgres@postgres/my_database" ``` +>**Note:** +Integers (as well as strings) are legal both for variable's name and value. +Floats are not legal and cannot be used. + These variables can be later used in all executed commands and scripts. The YAML-defined variables are also set to all created service containers, thus allowing to fine tune them. Variables can be also defined on a @@ -1152,7 +1156,7 @@ Example: ```yaml variables: - GET_SOURCES_ATTEMPTS: "3" + GET_SOURCES_ATTEMPTS: 3 ``` You can set them in the global [`variables`](#variables) section or the diff --git a/lib/gitlab/ci/config/entry/legacy_validation_helpers.rb b/lib/gitlab/ci/config/entry/legacy_validation_helpers.rb index 9b9a0a8125a68af29224c969ebbb8d4dbd49e6ce..a78a85397bd89dad71d0a1b6df8370bae22a9ccb 100644 --- a/lib/gitlab/ci/config/entry/legacy_validation_helpers.rb +++ b/lib/gitlab/ci/config/entry/legacy_validation_helpers.rb @@ -21,7 +21,13 @@ module Gitlab def validate_variables(variables) variables.is_a?(Hash) && - variables.all? { |key, value| validate_string(key) && validate_string(value) } + variables.flatten.all? do |value| + validate_string(value) || validate_integer(value) + end + end + + def validate_integer(value) + value.is_a?(Integer) end def validate_string(value) diff --git a/lib/gitlab/ci/config/entry/variables.rb b/lib/gitlab/ci/config/entry/variables.rb index c3b0e651c3a91a2edb1510326196c3dde6f7ab96..8acab605c91a68a6f14d6d3c203e32dbfdf8b346 100644 --- a/lib/gitlab/ci/config/entry/variables.rb +++ b/lib/gitlab/ci/config/entry/variables.rb @@ -15,6 +15,10 @@ module Gitlab def self.default {} end + + def value + Hash[@config.map { |key, value| [key.to_s, value.to_s] }] + end end end end diff --git a/spec/lib/gitlab/ci/config/entry/global_spec.rb b/spec/lib/gitlab/ci/config/entry/global_spec.rb index cf03acbfd3ab1a034b23df0594019c257c02fbf3..23270ad5053a4acc537fbfd7d111ecfaf0ab1ff7 100644 --- a/spec/lib/gitlab/ci/config/entry/global_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/global_spec.rb @@ -113,7 +113,7 @@ describe Gitlab::Ci::Config::Entry::Global do describe '#variables_value' do it 'returns variables' do - expect(global.variables_value).to eq(VAR: 'value') + expect(global.variables_value).to eq('VAR' => 'value') end end @@ -154,7 +154,7 @@ describe Gitlab::Ci::Config::Entry::Global do services: ['postgres:9.1', 'mysql:5.5'], stage: 'test', cache: { key: 'k', untracked: true, paths: ['public/'] }, - variables: { VAR: 'value' }, + variables: { 'VAR' => 'value' }, ignore: false, after_script: ['make clean'] }, spinach: { name: :spinach, diff --git a/spec/lib/gitlab/ci/config/entry/variables_spec.rb b/spec/lib/gitlab/ci/config/entry/variables_spec.rb index f15f02f403edfda32f44bfd783b06692e895add4..84bfef9e8ad7880d19c70d4e75f60e7d170dc332 100644 --- a/spec/lib/gitlab/ci/config/entry/variables_spec.rb +++ b/spec/lib/gitlab/ci/config/entry/variables_spec.rb @@ -13,6 +13,14 @@ describe Gitlab::Ci::Config::Entry::Variables do it 'returns hash with key value strings' do expect(entry.value).to eq config end + + context 'with numeric keys and values in the config' do + let(:config) { { 10 => 20 } } + + it 'converts numeric key and numeric value into strings' do + expect(entry.value).to eq('10' => '20') + end + end end describe '#errors' do