Commit 295cecfb authored by blackst0ne's avatar blackst0ne

Allow numeric values in gitlab-ci.yml

parent 1005389f
---
title: Allow numeric values in gitlab-ci.yml
merge_request: 10607
author: blackst0ne
...@@ -147,6 +147,10 @@ variables: ...@@ -147,6 +147,10 @@ variables:
DATABASE_URL: "postgres://postgres@postgres/my_database" 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. These variables can be later used in all executed commands and scripts.
The YAML-defined variables are also set to all created service containers, 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 thus allowing to fine tune them. Variables can be also defined on a
...@@ -1147,7 +1151,7 @@ Example: ...@@ -1147,7 +1151,7 @@ Example:
```yaml ```yaml
variables: variables:
GET_SOURCES_ATTEMPTS: "3" GET_SOURCES_ATTEMPTS: 3
``` ```
You can set them in the global [`variables`](#variables) section or the You can set them in the global [`variables`](#variables) section or the
......
...@@ -21,7 +21,13 @@ module Gitlab ...@@ -21,7 +21,13 @@ module Gitlab
def validate_variables(variables) def validate_variables(variables)
variables.is_a?(Hash) && 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 end
def validate_string(value) def validate_string(value)
......
...@@ -15,6 +15,10 @@ module Gitlab ...@@ -15,6 +15,10 @@ module Gitlab
def self.default def self.default
{} {}
end end
def value
Hash[@config.map { |key, value| [key.to_s, value.to_s] }]
end
end end
end end
end end
......
...@@ -113,7 +113,7 @@ describe Gitlab::Ci::Config::Entry::Global do ...@@ -113,7 +113,7 @@ describe Gitlab::Ci::Config::Entry::Global do
describe '#variables_value' do describe '#variables_value' do
it 'returns variables' do it 'returns variables' do
expect(global.variables_value).to eq(VAR: 'value') expect(global.variables_value).to eq('VAR' => 'value')
end end
end end
...@@ -154,7 +154,7 @@ describe Gitlab::Ci::Config::Entry::Global do ...@@ -154,7 +154,7 @@ describe Gitlab::Ci::Config::Entry::Global do
services: ['postgres:9.1', 'mysql:5.5'], services: ['postgres:9.1', 'mysql:5.5'],
stage: 'test', stage: 'test',
cache: { key: 'k', untracked: true, paths: ['public/'] }, cache: { key: 'k', untracked: true, paths: ['public/'] },
variables: { VAR: 'value' }, variables: { 'VAR' => 'value' },
ignore: false, ignore: false,
after_script: ['make clean'] }, after_script: ['make clean'] },
spinach: { name: :spinach, spinach: { name: :spinach,
......
...@@ -13,6 +13,14 @@ describe Gitlab::Ci::Config::Entry::Variables do ...@@ -13,6 +13,14 @@ describe Gitlab::Ci::Config::Entry::Variables do
it 'returns hash with key value strings' do it 'returns hash with key value strings' do
expect(entry.value).to eq config expect(entry.value).to eq config
end 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 end
describe '#errors' do describe '#errors' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment