Use Project.cache_index in Build#cache
This commit is contained in:
parent
0a002e230b
commit
771b97394a
2 changed files with 41 additions and 1 deletions
|
@ -461,8 +461,12 @@ module Ci
|
||||||
end
|
end
|
||||||
|
|
||||||
def cache
|
def cache
|
||||||
|
if options[:cache] && project.cache_index
|
||||||
|
options[:cache].merge(key: "#{options[:cache][:key]}:#{project.cache_index}")
|
||||||
|
else
|
||||||
[options[:cache]]
|
[options[:cache]]
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def credentials
|
def credentials
|
||||||
Gitlab::Ci::Build::Credentials::Factory.new(self).create!
|
Gitlab::Ci::Build::Credentials::Factory.new(self).create!
|
||||||
|
|
|
@ -255,6 +255,42 @@ describe Ci::Build do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#cache' do
|
||||||
|
let(:options) { { cache: { key: "key", paths: ["public"], policy: "pull-push" } } }
|
||||||
|
|
||||||
|
subject { build.cache }
|
||||||
|
|
||||||
|
context 'when build has cache' do
|
||||||
|
before do
|
||||||
|
allow(build).to receive(:options).and_return(options)
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when project has cache_index' do
|
||||||
|
before do
|
||||||
|
allow_any_instance_of(Project).to receive(:cache_index).and_return(1)
|
||||||
|
end
|
||||||
|
|
||||||
|
it { is_expected.to include(key: "key:1") }
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when project does not have cache_index' do
|
||||||
|
before do
|
||||||
|
allow_any_instance_of(Project).to receive(:cache_index).and_return(nil)
|
||||||
|
end
|
||||||
|
|
||||||
|
it { is_expected.to eq([options[:cache]]) }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when build does not have cache' do
|
||||||
|
before do
|
||||||
|
allow(build).to receive(:options).and_return({})
|
||||||
|
end
|
||||||
|
|
||||||
|
it { is_expected.to eq([nil]) }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe '#depends_on_builds' do
|
describe '#depends_on_builds' do
|
||||||
let!(:build) { create(:ci_build, pipeline: pipeline, name: 'build', stage_idx: 0, stage: 'build') }
|
let!(:build) { create(:ci_build, pipeline: pipeline, name: 'build', stage_idx: 0, stage: 'build') }
|
||||||
let!(:rspec_test) { create(:ci_build, pipeline: pipeline, name: 'rspec', stage_idx: 1, stage: 'test') }
|
let!(:rspec_test) { create(:ci_build, pipeline: pipeline, name: 'rspec', stage_idx: 1, stage: 'test') }
|
||||||
|
|
Loading…
Reference in a new issue