Commit 01c02ac0 authored by Marius Bobin's avatar Marius Bobin Committed by Douglas Barbosa Alexandre

Add pipeline ID and URL for downstream variables

Allows bridge jobs to expand variables that use
CI_PIPELINE_ID and CI_PIPELINE_URL
parent d8058520
...@@ -130,7 +130,9 @@ module EE ...@@ -130,7 +130,9 @@ module EE
end end
def downstream_variables def downstream_variables
scoped_variables.to_runner_variables.yield_self do |all_variables| variables = scoped_variables.concat(pipeline.persisted_variables)
variables.to_runner_variables.yield_self do |all_variables|
yaml_variables.to_a.map do |hash| yaml_variables.to_a.map do |hash|
{ key: hash[:key], value: ::ExpandVariables.expand(hash[:value], all_variables) } { key: hash[:key], value: ::ExpandVariables.expand(hash[:value], all_variables) }
end end
......
---
title: Pass pipeline variables when expanding Bridge downstream variables.
merge_request: 18875
author:
type: fixed
...@@ -225,13 +225,40 @@ describe Ci::Bridge do ...@@ -225,13 +225,40 @@ describe Ci::Bridge do
end end
context 'when using variables interpolation' do context 'when using variables interpolation' do
let(:yaml_variables) do
[
{
key: 'EXPANDED',
value: '$BRIDGE-bridge',
public: true
},
{
key: 'UPSTREAM_CI_PIPELINE_ID',
value: '$CI_PIPELINE_ID',
public: true
},
{
key: 'UPSTREAM_CI_PIPELINE_URL',
value: '$CI_PIPELINE_URL',
public: true
}
]
end
before do before do
bridge.yaml_variables << { key: 'EXPANDED', value: '$BRIDGE-bridge', public: true } bridge.yaml_variables.concat(yaml_variables)
end end
it 'correctly expands variables with interpolation' do it 'correctly expands variables with interpolation' do
expanded_values = pipeline
.persisted_variables
.to_hash
.transform_keys { |key| "UPSTREAM_#{key}" }
.map { |key, value| { key: key, value: value } }
.push(key: 'EXPANDED', value: 'cross-bridge')
expect(bridge.downstream_variables) expect(bridge.downstream_variables)
.to include(key: 'EXPANDED', value: 'cross-bridge') .to match(a_collection_including(*expanded_values))
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