Commit ac9d7929 authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch 'set-default-cache-key-for-jobs' into 'master'

Set default cache key to 'default' for jobs

Closes #22419

See merge request !9666
parents 74bfa890 23198320
---
title: Set default cache key to "default" for jobs
merge_request: 9666
author:
......@@ -166,10 +166,11 @@ which can be set in GitLab's UI.
cached between jobs. You can only use paths that are within the project
workspace.
**By default the caching is enabled per-job and per-branch.**
**By default caching is enabled and shared between pipelines and jobs,
starting from GitLab 9.0**
If `cache` is defined outside the scope of the jobs, it means it is set
globally and all jobs will use its definition.
If `cache` is defined outside the scope of jobs, it means it is set
globally and all jobs will use that definition.
Cache all files in `binaries` and `.config`:
......@@ -202,7 +203,7 @@ rspec:
- binaries/
```
Locally defined cache overwrites globally defined options. The following `rspec`
Locally defined cache overrides globally defined options. The following `rspec`
job will cache only `binaries/`:
```yaml
......@@ -213,10 +214,15 @@ cache:
rspec:
script: test
cache:
key: rspec
paths:
- binaries/
```
Note that since cache is shared between jobs, if you're using different
paths for different jobs, you should also set a different **cache:key**
otherwise cache content can be overwritten.
The cache is provided on a best-effort basis, so don't expect that the cache
will be always present. For implementation details, please check GitLab Runner.
......@@ -233,6 +239,9 @@ different jobs or even different branches.
The `cache:key` variable can use any of the [predefined variables](../variables/README.md).
The default key is **default** across the project, therefore everything is
shared between each pipelines and jobs by default, starting from GitLab 9.0.
---
**Example configurations**
......
......@@ -22,6 +22,12 @@ module Gitlab
entry :paths, Entry::Paths,
description: 'Specify which paths should be cached across builds.'
helpers :key
def value
super.merge(key: key_value)
end
end
end
end
......
......@@ -11,6 +11,10 @@ module Gitlab
validations do
validates :config, key: true
end
def self.default
'default'
end
end
end
end
......
......@@ -70,6 +70,12 @@ module Gitlab
true
end
def inspect
val = leaf? ? config : descendants
unspecified = specified? ? '' : '(unspecified) '
"#<#{self.class.name} #{unspecified}{#{key}: #{val.inspect}}>"
end
def self.default
end
......
......@@ -29,6 +29,10 @@ module Gitlab
def relevant?
false
end
def inspect
"#<#{self.class.name}>"
end
end
end
end
......
......@@ -24,6 +24,20 @@ describe Gitlab::Ci::Config::Entry::Cache do
expect(entry).to be_valid
end
end
context 'when key is missing' do
let(:config) do
{ untracked: true,
paths: ['some/path/'] }
end
describe '#value' do
it 'sets key with the default' do
expect(entry.value[:key])
.to eq(Gitlab::Ci::Config::Entry::Key.default)
end
end
end
end
context 'when entry value is not correct' do
......
......@@ -60,13 +60,13 @@ describe Gitlab::Ci::Config::Entry::Factory do
end
context 'when creating entry with nil value' do
it 'creates an undefined entry' do
it 'creates an unspecified entry' do
entry = factory
.value(nil)
.create!
expect(entry)
.to be_an_instance_of Gitlab::Ci::Config::Entry::Unspecified
.not_to be_specified
end
end
......
......@@ -188,7 +188,7 @@ describe Gitlab::Ci::Config::Entry::Global do
it 'contains unspecified nodes' do
expect(global.descendants.first)
.to be_an_instance_of Gitlab::Ci::Config::Entry::Unspecified
.not_to be_specified
end
end
......
......@@ -31,4 +31,10 @@ describe Gitlab::Ci::Config::Entry::Key do
end
end
end
describe '.default' do
it 'returns default key' do
expect(described_class.default).to eq 'default'
end
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