diff --git a/ee/lib/ee/gitlab/ci/config/entry/bridge.rb b/ee/lib/ee/gitlab/ci/config/entry/bridge.rb index 3bb423ccaa08841cdcd8f2ccd4a48c3ac989a7a9..378c942e0221bb251c86562e489ae318211b366b 100644 --- a/ee/lib/ee/gitlab/ci/config/entry/bridge.rb +++ b/ee/lib/ee/gitlab/ci/config/entry/bridge.rb @@ -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 diff --git a/ee/spec/lib/ee/gitlab/ci/config/entry/bridge_spec.rb b/ee/spec/lib/ee/gitlab/ci/config/entry/bridge_spec.rb index 7440044f429efa736eca707a09611a8e41e61778..f4a89ad8c5f6146f2b9f17b2c58d0f4be264f9fa 100644 --- a/ee/spec/lib/ee/gitlab/ci/config/entry/bridge_spec.rb +++ b/ee/spec/lib/ee/gitlab/ci/config/entry/bridge_spec.rb @@ -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 } diff --git a/ee/spec/models/ci/bridge_spec.rb b/ee/spec/models/ci/bridge_spec.rb index 1f134c29c68ea609c00547a99405cc91f14ac4d0..7610b8c5dd6e676270bd0217f03eae57a5cfe8fc 100644 --- a/ee/spec/models/ci/bridge_spec.rb +++ b/ee/spec/models/ci/bridge_spec.rb @@ -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 diff --git a/ee/spec/services/ci/create_pipeline_service_spec.rb b/ee/spec/services/ci/create_pipeline_service_spec.rb index 3d3cf1b15e9a63735914def5fd90c776dd0b67f9..c5441d30212e4227daf3f9a01aa45b6dba42e80a 100644 --- a/ee/spec/services/ci/create_pipeline_service_spec.rb +++ b/ee/spec/services/ci/create_pipeline_service_spec.rb @@ -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