zj nice catches

This commit is contained in:
Shinya Maeda 2017-06-27 16:55:27 +09:00
parent cfd5caa5e7
commit d65d66e08b
5 changed files with 12 additions and 15 deletions

View File

@ -193,7 +193,7 @@ module Ci
variables += user_variables
variables += project.secret_variables_for(ref).map(&:to_runner_variable)
variables += trigger_request&.user_variables || []
variables += pipeline.pipeline_schedule&.variables&.map(&:to_runner_variable) || []
variables += pipeline.pipeline_schedule&.job_variables
variables
end

View File

@ -59,5 +59,9 @@ module Ci
Gitlab::Ci::CronParser.new(worker_cron, worker_time_zone)
.next_time_from(next_run_at)
end
def job_variables
variables&.map(&:to_runner_variable) || []
end
end
end

View File

@ -1369,20 +1369,18 @@ describe Ci::Build, :models do
it { is_expected.to include(predefined_trigger_variable) }
end
context 'when build was triggered by scheduled pipeline' do
let(:secret_variable) do
{ key: 'SECRET_KEY', value: 'secret_value', public: false }
end
context 'when a job was triggered by a pipeline schedule' do
let(:pipeline_schedule) { create(:ci_pipeline_schedule, project: project) }
let!(:pipeline_schedule_variable) do
create(:ci_pipeline_schedule_variable, key: 'SCHEDULE_VARIABLE_KEY',
pipeline_schedule: pipeline_schedule)
end
before do
pipeline_schedule.pipelines << pipeline
create(:ci_pipeline_schedule_variable,
secret_variable.slice(:key, :value).merge(pipeline_schedule: pipeline_schedule))
end
it { is_expected.to include(secret_variable) }
it { is_expected.to include(pipeline_schedule_variable.to_runner_variable) }
end
context 'when yaml_variables are undefined' do

View File

@ -121,17 +121,12 @@ describe Ci::PipelineSchedule, models: true do
describe '#job_variables' do
let!(:pipeline_schedule) { create(:ci_pipeline_schedule, :nightly) }
let!(:pipeline_schedule_variables) do
create_list(:ci_pipeline_schedule_variable, 2, pipeline_schedule: pipeline_schedule)
end
subject { pipeline_schedule.job_variables }
before do
pipeline_schedule.reload
end
it { is_expected.to eq(pipeline_schedule_variables.map(&:to_runner_variable)) }
end
end

View File

@ -3,6 +3,6 @@ require 'spec_helper'
describe Ci::PipelineScheduleVariable, models: true do
subject { build(:ci_pipeline_schedule_variable) }
it { is_expected.to be_kind_of(HasVariable) }
it { is_expected.to include_module(HasVariable) }
it { is_expected.to validate_uniqueness_of(:key).scoped_to(:pipeline_schedule_id) }
end