Commit 634bb820 authored by Marius Bobin's avatar Marius Bobin

Refactor pipeline schedule variables

Changelog: other
parent 15e1fb16
......@@ -28,7 +28,7 @@ module Gitlab
variables.concat(secret_project_variables(environment: environment))
variables.concat(job.trigger_request.user_variables) if job.trigger_request
variables.concat(pipeline.variables)
variables.concat(pipeline.pipeline_schedule.job_variables) if pipeline.pipeline_schedule
variables.concat(pipeline_schedule_variables)
end
end
......@@ -120,6 +120,18 @@ module Gitlab
end
end
def pipeline_schedule_variables
strong_memoize(:pipeline_schedule_variables) do
variables = if pipeline.pipeline_schedule
pipeline.pipeline_schedule.job_variables
else
[]
end
Gitlab::Ci::Variables::Collection.new(variables)
end
end
def ci_node_total_value(job)
parallel = job.options&.dig(:parallel)
parallel = parallel.dig(:total) if parallel.is_a?(Hash)
......
......@@ -199,6 +199,20 @@ RSpec.describe Gitlab::Ci::Variables::Builder do
'O' => '15', 'P' => '15')
end
end
context 'with schedule variables' do
let_it_be(:schedule) { create(:ci_pipeline_schedule, project: project) }
let_it_be(:schedule_variable) { create(:ci_pipeline_schedule_variable, pipeline_schedule: schedule) }
before do
pipeline.update!(pipeline_schedule_id: schedule.id)
end
it 'includes schedule variables' do
expect(subject.to_runner_variables)
.to include(a_hash_including(key: schedule_variable.key, value: schedule_variable.value))
end
end
end
describe '#user_variables' do
......
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