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
include ::Gitlab::Config::Entry::Attributable
ALLOWED_KEYS = %i[trigger stage allow_failure only except
when extends].freeze
when extends variables].freeze
validations do
validates :config, allowed_keys: ALLOWED_KEYS
......@@ -44,6 +44,9 @@ module EE
entry :except, ::Gitlab::Ci::Config::Entry::Policy,
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)
attributes(*ALLOWED_KEYS)
......@@ -58,6 +61,7 @@ module EE
stage: stage_value,
when: when_value,
extends: extends_value,
variables: (variables_value if variables_defined?),
only: only_value,
except: except_value }.compact
end
......
......@@ -54,7 +54,8 @@ describe EE::Gitlab::Ci::Config::Entry::Bridge do
extends: '.some-key',
stage: 'deploy',
only: { variables: %w[$SOMEVARIABLE] },
except: { refs: %w[feature] } }
except: { refs: %w[feature] },
variables: { VARIABLE: '123' } }
end
it { is_expected.to be_valid }
......
......@@ -5,7 +5,9 @@ describe Ci::Bridge do
set(:pipeline) { create(:ci_pipeline, project: project) }
let(:bridge) do
create(:ci_bridge, status: :created, options: options, pipeline: pipeline)
create(:ci_bridge, :variables, status: :created,
options: options,
pipeline: pipeline)
end
let(:options) do
......@@ -63,4 +65,18 @@ describe Ci::Bridge do
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
......@@ -77,6 +77,8 @@ describe Ci::CreatePipelineService, '#execute' do
script: rspec
deploy:
variables:
CROSS: downstream
stage: deploy
trigger: my/project
YAML
......@@ -94,6 +96,8 @@ describe Ci::CreatePipelineService, '#execute' do
expect(bridge.stage).to eq 'deploy'
expect(pipeline.statuses).to match_array [test, bridge]
expect(bridge.options).to eq(trigger: { project: 'my/project' })
expect(bridge.yaml_variables)
.to include(key: 'CROSS', value: 'downstream', public: true)
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