Commit b578fbfb authored by Grzegorz Bizon's avatar Grzegorz Bizon 🔴

Make it possible to override build variables

parent a1363d39
......@@ -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
......
......@@ -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'],
......
......@@ -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
......
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