Make it possible to override build variables

This commit is contained in:
Grzegorz Bizon
2016-04-18 13:17:47 +02:00
parent a1363d39c6
commit b578fbfb85
3 changed files with 22 additions and 7 deletions
+2 -1
View File
@@ -147,7 +147,8 @@ module Ci
end
def variables
predefined_variables + yaml_variables + project_variables + trigger_variables
(predefined_variables + yaml_variables + project_variables + trigger_variables)
.reverse.uniq { |var| var[:key] }.reverse
end
def merge_request
+1 -1
View File
@@ -364,7 +364,7 @@ module Ci
end
context 'when job variables are defined' do
let(:job_variables) { { KEY1: 'value1', SOME_KEY_2: 'value2'} }
let(:job_variables) { { KEY1: 'value1', SOME_KEY_2: 'value2' } }
let(:yaml_config) do
YAML.dump(
{ before_script: ['pwd'],
+19 -5
View File
@@ -240,17 +240,31 @@ describe Ci::Build, models: true do
end
context 'when job variables are defined' do
def result_variables
job_variables.map do |key, value|
{ key: key, value: value, public: true }
end
end
before { build.update_attribute(:options, variables: job_variables) }
context 'when job variables are unique' do
let(:job_variables) { { KEY1: 'value1', KEY2: 'value2' } }
let(:resulting_variables) do
[{ key: :KEY1, value: 'value1', public: true },
{ key: :KEY2, value: 'value2', public: true }]
end
it 'includes job variables' do
expect(subject).to include(*resulting_variables)
expect(subject).to include(*result_variables)
end
end
context 'when job variable has same key other variable has' do
let(:job_variables) { { CI_BUILD_NAME: 'overridden' } }
it 'contains job yaml variable' do
expect(subject).to include(*result_variables)
end
it 'contains only one variable with this key' do
expect(subject.count { |var| var[:key] == :CI_BUILD_NAME } ).to eq 1
end
end
end