Commit 825d32d0 authored by Furkan Ayhan's avatar Furkan Ayhan Committed by Jan Provaznik

Add pipeline schedule variables to forward:pipeline

Pipeline schedule variables have the same priority
as pipeline variables.
We decided that we could consider pipeline schedule variables
as pipeline variables.
parent 67ec3230
...@@ -1291,7 +1291,7 @@ ...@@ -1291,7 +1291,7 @@
}, },
"pipeline_variables": { "pipeline_variables": {
"type": "boolean", "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 "default": false
} }
} }
...@@ -1407,7 +1407,7 @@ ...@@ -1407,7 +1407,7 @@
}, },
"pipeline_variables": { "pipeline_variables": {
"type": "boolean", "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 "default": false
} }
} }
......
...@@ -274,7 +274,8 @@ module Ci ...@@ -274,7 +274,8 @@ module Ci
# The order of this list refers to the priority of the variables # The order of this list refers to the priority of the variables
downstream_yaml_variables(expand_variables) + downstream_yaml_variables(expand_variables) +
downstream_pipeline_variables(expand_variables) downstream_pipeline_variables(expand_variables) +
downstream_pipeline_schedule_variables(expand_variables)
end end
def downstream_yaml_variables(expand_variables) def downstream_yaml_variables(expand_variables)
...@@ -293,6 +294,15 @@ module Ci ...@@ -293,6 +294,15 @@ module Ci
end end
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? def forward_yaml_variables?
strong_memoize(:forward_yaml_variables) do strong_memoize(:forward_yaml_variables) do
result = options&.dig(:trigger, :forward, :yaml_variables) result = options&.dig(:trigger, :forward, :yaml_variables)
......
...@@ -3713,7 +3713,7 @@ and [multi-project pipelines](../pipelines/multi_project_pipelines.md). ...@@ -3713,7 +3713,7 @@ and [multi-project pipelines](../pipelines/multi_project_pipelines.md).
- `yaml_variables`: `true` (default), or `false`. When `true`, variables defined - `yaml_variables`: `true` (default), or `false`. When `true`, variables defined
in the trigger job are passed to downstream pipelines. 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. are passed to downstream pipelines.
**Example of `trigger:forward`**: **Example of `trigger:forward`**:
......
...@@ -288,6 +288,26 @@ RSpec.describe Ci::Bridge do ...@@ -288,6 +288,26 @@ RSpec.describe Ci::Bridge do
) )
end end
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
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