diff --git a/app/assets/javascripts/editor/schema/ci.json b/app/assets/javascripts/editor/schema/ci.json index 2d222903c0c069d415ec0792da5f93a5cc6c1fdc..fe3229ac91b10cdeeed8083dc270d83ce6b9b85b 100644 --- a/app/assets/javascripts/editor/schema/ci.json +++ b/app/assets/javascripts/editor/schema/ci.json @@ -1291,7 +1291,7 @@ }, "pipeline_variables": { "type": "boolean", - "description": "Variables added for manual pipeline runs are passed to downstream pipelines.", + "description": "Variables added for manual pipeline runs and scheduled pipelines are passed to downstream pipelines.", "default": false } } @@ -1407,7 +1407,7 @@ }, "pipeline_variables": { "type": "boolean", - "description": "Variables added for manual pipeline runs are passed to downstream pipelines.", + "description": "Variables added for manual pipeline runs and scheduled pipelines are passed to downstream pipelines.", "default": false } } diff --git a/app/models/ci/bridge.rb b/app/models/ci/bridge.rb index cfc23608124a3daba9ff66fd6bcc6aec466740cd..ff444ddefa39ffd1030b93355d363357b5c7f24c 100644 --- a/app/models/ci/bridge.rb +++ b/app/models/ci/bridge.rb @@ -274,7 +274,8 @@ def calculate_downstream_variables # The order of this list refers to the priority of the variables downstream_yaml_variables(expand_variables) + - downstream_pipeline_variables(expand_variables) + downstream_pipeline_variables(expand_variables) + + downstream_pipeline_schedule_variables(expand_variables) end def downstream_yaml_variables(expand_variables) @@ -293,6 +294,15 @@ def downstream_pipeline_variables(expand_variables) end end + def downstream_pipeline_schedule_variables(expand_variables) + return [] unless forward_pipeline_variables? + return [] unless pipeline.pipeline_schedule + + pipeline.pipeline_schedule.variables.to_a.map do |variable| + { key: variable.key, value: ::ExpandVariables.expand(variable.value, expand_variables) } + end + end + def forward_yaml_variables? strong_memoize(:forward_yaml_variables) do result = options&.dig(:trigger, :forward, :yaml_variables) diff --git a/doc/ci/yaml/index.md b/doc/ci/yaml/index.md index 8ddeb3a5aa8ebd5c02de8962ac08792762efba41..b335e8e8545d2ae7e8614d9ad92167cfd4804afd 100644 --- a/doc/ci/yaml/index.md +++ b/doc/ci/yaml/index.md @@ -3714,7 +3714,7 @@ and [multi-project pipelines](../pipelines/multi_project_pipelines.md). - `yaml_variables`: `true` (default), or `false`. When `true`, variables defined in the trigger job are passed to downstream pipelines. -- `pipeline_variables`: `true` or `false` (default). When `true`, [manual pipeline variables](../variables/index.md#override-a-defined-cicd-variable) +- `pipeline_variables`: `true` or `false` (default). When `true`, [manual pipeline variables](../variables/index.md#override-a-defined-cicd-variable) and [scheduled pipeline variables](../pipelines/schedules.md#add-a-pipeline-schedule) are passed to downstream pipelines. **Example of `trigger:forward`**: diff --git a/spec/models/ci/bridge_spec.rb b/spec/models/ci/bridge_spec.rb index 6f25f2879a4f9bc19fc90ed7ea515c45d284f34d..5ee560c4925af7a2c7e0e9acbe43d6ef116fb81b 100644 --- a/spec/models/ci/bridge_spec.rb +++ b/spec/models/ci/bridge_spec.rb @@ -288,6 +288,26 @@ ) end end + + context 'when the pipeline runs from a pipeline schedule' do + let(:pipeline_schedule) { create(:ci_pipeline_schedule, :nightly, project: project ) } + let(:pipeline) { create(:ci_pipeline, pipeline_schedule: pipeline_schedule) } + + let(:options) do + { trigger: { project: 'my/project', forward: { pipeline_variables: true } } } + end + + before do + pipeline_schedule.variables.create!(key: 'schedule_var_key', value: 'schedule var value') + end + + it 'adds the schedule variable' do + expect(bridge.downstream_variables).to contain_exactly( + { key: 'BRIDGE', value: 'cross' }, + { key: 'schedule_var_key', value: 'schedule var value' } + ) + end + end end end