Commit 408248f4 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Make it possible to define downstream bridge variables

It is now possible to pass variables to a downstream pipeline from a
bridge job. Variables defined as YAML variables for this bridge job are
going to be populated downstream, and are going to be available in every
job created within a downstream pipeline. These variables are then going
to be passed to GitLab Runner as environment variables.
parent 92c694e8
...@@ -14,7 +14,7 @@ module EE ...@@ -14,7 +14,7 @@ module EE
include ::Gitlab::Config::Entry::Attributable include ::Gitlab::Config::Entry::Attributable
ALLOWED_KEYS = %i[trigger stage allow_failure only except ALLOWED_KEYS = %i[trigger stage allow_failure only except
when extends].freeze when extends variables].freeze
validations do validations do
validates :config, allowed_keys: ALLOWED_KEYS validates :config, allowed_keys: ALLOWED_KEYS
...@@ -44,6 +44,9 @@ module EE ...@@ -44,6 +44,9 @@ module EE
entry :except, ::Gitlab::Ci::Config::Entry::Policy, entry :except, ::Gitlab::Ci::Config::Entry::Policy,
description: 'Refs policy this job will be executed for.' description: 'Refs policy this job will be executed for.'
entry :variables, ::Gitlab::Ci::Config::Entry::Variables,
description: 'Environment variables available for this job.'
helpers(*ALLOWED_KEYS) helpers(*ALLOWED_KEYS)
attributes(*ALLOWED_KEYS) attributes(*ALLOWED_KEYS)
...@@ -58,6 +61,7 @@ module EE ...@@ -58,6 +61,7 @@ module EE
stage: stage_value, stage: stage_value,
when: when_value, when: when_value,
extends: extends_value, extends: extends_value,
variables: (variables_value if variables_defined?),
only: only_value, only: only_value,
except: except_value }.compact except: except_value }.compact
end end
......
...@@ -54,7 +54,8 @@ describe EE::Gitlab::Ci::Config::Entry::Bridge do ...@@ -54,7 +54,8 @@ describe EE::Gitlab::Ci::Config::Entry::Bridge do
extends: '.some-key', extends: '.some-key',
stage: 'deploy', stage: 'deploy',
only: { variables: %w[$SOMEVARIABLE] }, only: { variables: %w[$SOMEVARIABLE] },
except: { refs: %w[feature] } } except: { refs: %w[feature] },
variables: { VARIABLE: '123' } }
end end
it { is_expected.to be_valid } it { is_expected.to be_valid }
......
...@@ -5,7 +5,9 @@ describe Ci::Bridge do ...@@ -5,7 +5,9 @@ describe Ci::Bridge do
set(:pipeline) { create(:ci_pipeline, project: project) } set(:pipeline) { create(:ci_pipeline, project: project) }
let(:bridge) do let(:bridge) do
create(:ci_bridge, status: :created, options: options, pipeline: pipeline) create(:ci_bridge, :variables, status: :created,
options: options,
pipeline: pipeline)
end end
let(:options) do let(:options) do
...@@ -63,4 +65,18 @@ describe Ci::Bridge do ...@@ -63,4 +65,18 @@ describe Ci::Bridge do
end end
end end
end end
describe '#yaml_variables' do
it 'returns YAML variables' do
expect(bridge.yaml_variables)
.to include(key: 'BRIDGE', value: 'cross', public: true)
end
end
describe '#downstream_variables' do
it 'returns variables that are going to be passed downstream' do
expect(bridge.downstream_variables)
.to include(key: 'BRIDGE', value: 'cross')
end
end
end end
...@@ -77,6 +77,8 @@ describe Ci::CreatePipelineService, '#execute' do ...@@ -77,6 +77,8 @@ describe Ci::CreatePipelineService, '#execute' do
script: rspec script: rspec
deploy: deploy:
variables:
CROSS: downstream
stage: deploy stage: deploy
trigger: my/project trigger: my/project
YAML YAML
...@@ -94,6 +96,8 @@ describe Ci::CreatePipelineService, '#execute' do ...@@ -94,6 +96,8 @@ describe Ci::CreatePipelineService, '#execute' do
expect(bridge.stage).to eq 'deploy' expect(bridge.stage).to eq 'deploy'
expect(pipeline.statuses).to match_array [test, bridge] expect(pipeline.statuses).to match_array [test, bridge]
expect(bridge.options).to eq(trigger: { project: 'my/project' }) expect(bridge.options).to eq(trigger: { project: 'my/project' })
expect(bridge.yaml_variables)
.to include(key: 'CROSS', value: 'downstream', public: true)
end 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