Commit 06f01073 authored by Shinya Maeda's avatar Shinya Maeda

pipeline_schedule_variables model/db

parent 8bc8e01f
...@@ -176,12 +176,9 @@ module Ci ...@@ -176,12 +176,9 @@ module Ci
# * Lowercased # * Lowercased
# * Anything not matching [a-z0-9-] is replaced with a - # * Anything not matching [a-z0-9-] is replaced with a -
# * Maximum length is 63 bytes # * Maximum length is 63 bytes
# * First/Last Character is not a hyphen
def ref_slug def ref_slug
ref.to_s slugified = ref.to_s.downcase
.downcase slugified.gsub(/[^a-z0-9]/, '-')[0..62]
.gsub(/[^a-z0-9]/, '-')[0..62]
.gsub(/(\A-+|-+\z)/, '')
end end
# Variables whose value does not depend on environment # Variables whose value does not depend on environment
...@@ -195,8 +192,11 @@ module Ci ...@@ -195,8 +192,11 @@ module Ci
variables += yaml_variables variables += yaml_variables
variables += user_variables variables += user_variables
variables += project.secret_variables_for(ref).map(&:to_runner_variable) variables += project.secret_variables_for(ref).map(&:to_runner_variable)
variables += trigger_request.user_variables if trigger_request if trigger_request
variables += pipeline.pipeline_schedule.job_variables if pipeline.pipeline_schedule variables += trigger_request.user_variables
elsif pipeline.pipeline_schedule
variables += pipeline.pipeline_schedule.variables.map(&:to_runner_variable)
end
variables variables
end end
......
...@@ -4,7 +4,6 @@ module Ci ...@@ -4,7 +4,6 @@ module Ci
include HasVariable include HasVariable
belongs_to :pipeline_schedule belongs_to :pipeline_schedule
validates :key, uniqueness: { scope: :pipeline_schedule_id } validates :key, uniqueness: { scope: :pipeline_schedule_id }
end end
end end
...@@ -10,7 +10,7 @@ class CreateCiPipelineScheduleVariables < ActiveRecord::Migration ...@@ -10,7 +10,7 @@ class CreateCiPipelineScheduleVariables < ActiveRecord::Migration
t.string :encrypted_value_iv t.string :encrypted_value_iv
t.integer :pipeline_schedule_id, null: false t.integer :pipeline_schedule_id, null: false
t.timestamps_with_timezone null: true t.timestamps null: false
end end
add_index :ci_pipeline_schedule_variables, add_index :ci_pipeline_schedule_variables,
......
...@@ -1004,11 +1004,7 @@ describe Ci::Build, :models do ...@@ -1004,11 +1004,7 @@ describe Ci::Build, :models do
'fix-1-foo' => 'fix-1-foo', 'fix-1-foo' => 'fix-1-foo',
'a' * 63 => 'a' * 63, 'a' * 63 => 'a' * 63,
'a' * 64 => 'a' * 63, 'a' * 64 => 'a' * 63,
'FOO' => 'foo', 'FOO' => 'foo'
'-' + 'a' * 61 + '-' => 'a' * 61,
'-' + 'a' * 62 + '-' => 'a' * 62,
'-' + 'a' * 63 + '-' => 'a' * 62,
'a' * 62 + ' ' => 'a' * 62
}.each do |ref, slug| }.each do |ref, slug|
it "transforms #{ref} to #{slug}" do it "transforms #{ref} to #{slug}" do
build.ref = ref build.ref = ref
...@@ -1373,21 +1369,20 @@ describe Ci::Build, :models do ...@@ -1373,21 +1369,20 @@ describe Ci::Build, :models do
it { is_expected.to include(predefined_trigger_variable) } it { is_expected.to include(predefined_trigger_variable) }
end end
context 'when a job was triggered by a pipeline schedule' do context 'when build was triggered by scheduled pipeline' do
let(:pipeline_schedule) { create(:ci_pipeline_schedule, project: project) } let(:secret_variable) do
{ key: 'SECRET_KEY', value: 'secret_value', public: false }
let!(:pipeline_schedule_variable) do
create(:ci_pipeline_schedule_variable,
key: 'SCHEDULE_VARIABLE_KEY',
pipeline_schedule: pipeline_schedule)
end end
let(:pipeline_schedule) { create(:ci_pipeline_schedule, project: project) }
before do before do
pipeline_schedule.pipelines << pipeline pipeline_schedule.pipelines << pipeline
pipeline_schedule.reload create(:ci_pipeline_schedule_variable,
secret_variable.slice(:key, :value).merge(pipeline_schedule: pipeline_schedule))
end end
it { is_expected.to include(pipeline_schedule_variable.to_runner_variable) } it { is_expected.to include(secret_variable) }
end end
context 'when yaml_variables are undefined' do context 'when yaml_variables are undefined' do
......
...@@ -3,6 +3,6 @@ require 'spec_helper' ...@@ -3,6 +3,6 @@ require 'spec_helper'
describe Ci::PipelineScheduleVariable, models: true do describe Ci::PipelineScheduleVariable, models: true do
subject { build(:ci_pipeline_schedule_variable) } subject { build(:ci_pipeline_schedule_variable) }
it { is_expected.to include_module(HasVariable) } it { is_expected.to be_kind_of(HasVariable) }
it { is_expected.to validate_uniqueness_of(:key).scoped_to(:pipeline_schedule_id) } it { is_expected.to validate_uniqueness_of(:key).scoped_to(:pipeline_schedule_id) }
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