summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorblackst0ne <blackst0ne.ru@gmail.com>2017-05-07 08:29:43 +1100
committerblackst0ne <blackst0ne.ru@gmail.com>2017-05-07 08:29:43 +1100
commit295cecfb56af4e064340d255140a28959c47b25d (patch)
treef88460655eddc755c56234c92b5e5f393867ede5
parent1005389f70070245092c1ae5f3f9b10b8e7c102e (diff)
downloadgitlab-ce-295cecfb56af4e064340d255140a28959c47b25d.tar.gz
Allow numeric values in gitlab-ci.yml
-rw-r--r--changelogs/unreleased/allow_numeric_values_in_gitlab_ci_yml.yml4
-rw-r--r--doc/ci/yaml/README.md6
-rw-r--r--lib/gitlab/ci/config/entry/legacy_validation_helpers.rb8
-rw-r--r--lib/gitlab/ci/config/entry/variables.rb4
-rw-r--r--spec/lib/gitlab/ci/config/entry/global_spec.rb4
-rw-r--r--spec/lib/gitlab/ci/config/entry/variables_spec.rb8
6 files changed, 30 insertions, 4 deletions
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 00000000000..8c7fa53a18b
--- /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 ad3ebd144df..1c34273f1b8 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
@@ -1147,7 +1151,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 9b9a0a8125a..a78a85397bd 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 c3b0e651c3a..8acab605c91 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 684d01e9056..7678d6ebe30 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 f15f02f403e..84bfef9e8ad 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