Commit 09b4e494 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Support passing bridge variables to downstream pipeline

parent dcaaacb0
...@@ -6,7 +6,11 @@ module EE ...@@ -6,7 +6,11 @@ module EE
extend ActiveSupport::Concern extend ActiveSupport::Concern
prepended do prepended do
serialize :options # rubocop:disable Cop/ActiveRecordSerialize # rubocop:disable Cop/ActiveRecordSerialize
serialize :options
serialize :yaml_variables, ::Gitlab::Serializer::Ci::Variables
# rubocop:enable Cop/ActiveRecordSerialize
has_many :sourced_pipelines, class_name: ::Ci::Sources::Pipeline, has_many :sourced_pipelines, class_name: ::Ci::Sources::Pipeline,
foreign_key: :source_job_id foreign_key: :source_job_id
...@@ -34,6 +38,10 @@ module EE ...@@ -34,6 +38,10 @@ module EE
def target_ref def target_ref
options&.dig(:trigger, :branch) options&.dig(:trigger, :branch)
end end
def downstream_variables
yaml_variables.map { |hash| hash.except(:public) }
end
end end
end end
end end
...@@ -43,6 +43,10 @@ module Ci ...@@ -43,6 +43,10 @@ module Ci
source_project: @bridge.project, source_project: @bridge.project,
project: target_project, project: target_project,
pipeline: pipeline) pipeline: pipeline)
# TODO we should use metadata with bridge jobs too.
#
pipeline.variables.build(@bridge.downstream_variables)
end end
end end
......
...@@ -141,5 +141,18 @@ describe Ci::CreateCrossProjectPipelineService, '#execute' do ...@@ -141,5 +141,18 @@ describe Ci::CreateCrossProjectPipelineService, '#execute' do
expect(bridge.failure_reason).to eq 'invalid_bridge_trigger' expect(bridge.failure_reason).to eq 'invalid_bridge_trigger'
end end
end end
context 'when bridge job has YAML variables defined' do
before do
bridge.yaml_variables = [{ key: 'BRIDGE', value: 'var', public: true }]
end
it 'passes bridge variables to downstream pipeline' do
pipeline = service.execute(bridge)
expect(pipeline.variables.first)
.to have_attributes(key: 'BRIDGE', value:'var')
end
end
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