summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShinya Maeda <shinya@gitlab.com>2017-06-27 16:55:27 +0900
committerShinya Maeda <shinya@gitlab.com>2017-07-05 18:38:27 +0900
commitd65d66e08bf62491fc4a3da322d36dfb9014eaac (patch)
tree1f49f6e9fbf7cb10f984ccafdb59fa15cd267e22
parentcfd5caa5e7d546436b82d94468defc0638270435 (diff)
downloadgitlab-ce-d65d66e08bf62491fc4a3da322d36dfb9014eaac.tar.gz
zj nice catches
-rw-r--r--app/models/ci/build.rb2
-rw-r--r--app/models/ci/pipeline_schedule.rb4
-rw-r--r--spec/models/ci/build_spec.rb14
-rw-r--r--spec/models/ci/pipeline_schedule_spec.rb5
-rw-r--r--spec/models/ci/pipeline_schedule_variable_spec.rb2
5 files changed, 12 insertions, 15 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb
index 12bc961ec87..ac5c2bf00ae 100644
--- a/app/models/ci/build.rb
+++ b/app/models/ci/build.rb
@@ -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
diff --git a/app/models/ci/pipeline_schedule.rb b/app/models/ci/pipeline_schedule.rb
index 440d9717fc8..df9df45edb0 100644
--- a/app/models/ci/pipeline_schedule.rb
+++ b/app/models/ci/pipeline_schedule.rb
@@ -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
diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb
index c6a7791d64b..8750cbcb13c 100644
--- a/spec/models/ci/build_spec.rb
+++ b/spec/models/ci/build_spec.rb
@@ -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
diff --git a/spec/models/ci/pipeline_schedule_spec.rb b/spec/models/ci/pipeline_schedule_spec.rb
index 54177bee5ce..2f826a91417 100644
--- a/spec/models/ci/pipeline_schedule_spec.rb
+++ b/spec/models/ci/pipeline_schedule_spec.rb
@@ -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
diff --git a/spec/models/ci/pipeline_schedule_variable_spec.rb b/spec/models/ci/pipeline_schedule_variable_spec.rb
index eb67792bf2f..9c0b0153e03 100644
--- a/spec/models/ci/pipeline_schedule_variable_spec.rb
+++ b/spec/models/ci/pipeline_schedule_variable_spec.rb
@@ -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