Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
c45a6bf3
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
c45a6bf3
编写于
1月 14, 2016
作者:
K
Kamil Trzcinski
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added cache:key to .gitlab-ci.yml allowing to fine tune the caching
上级
714f95b2
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
86 addition
and
8 deletion
+86
-8
CHANGELOG
CHANGELOG
+1
-0
doc/ci/yaml/README.md
doc/ci/yaml/README.md
+56
-4
lib/ci/gitlab_ci_yaml_processor.rb
lib/ci/gitlab_ci_yaml_processor.rb
+8
-0
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
+21
-4
未找到文件。
CHANGELOG
浏览文件 @
c45a6bf3
...
...
@@ -74,6 +74,7 @@ v 8.4.0 (unreleased)
- Fix: Creator should be added as a master of the project on creation
- Added X-GitLab-... headers to emails from CI and Email On Push services (Anton Baklanov)
- Add IP check against DNSBLs at account sign-up
- Added cache:key to .gitlab-ci.yml allowing to fine tune the caching
v 8.3.4
- Use gitlab-workhorse 0.5.4 (fixes API routing bug)
...
...
doc/ci/yaml/README.md
浏览文件 @
c45a6bf3
...
...
@@ -135,10 +135,9 @@ thus allowing to fine tune them.
### cache
`cache`
is used to specify a list of files and directories which should be
cached between builds. Caches are stored according to the branch/ref and the
job name. They are not currently shared between different job names or between
branches/refs, which means that caching will benefit you if you push subsequent
commits to an existing feature branch.
cached between builds.
**By default the caching is enabled per-job and per-branch.**
If
`cache`
is defined outside the scope of the jobs, it means it is set
globally and all jobs will use its definition.
...
...
@@ -152,6 +151,59 @@ cache:
-
binaries/
```
#### cache:key
_**Note:** Introduced in GitLab Runner v1.0.0._
The
`key`
directive allows you to define the affinity of caching
between jobs, allowing to have a single cache for all jobs,
cache per-job, cache per-branch or any other way you deem proper.
This allows you to fine tune caching, allowing you to cache data between different jobs or even different branches.
The
`cache:key`
variable can use any of the
[
predefined variables
](
../variables/README.md
)
:
Example configurations:
To enable per-job caching:
```yaml
cache:
key: "$CI_BUILD_NAME"
untracked: true
```
To enable per-branch caching:
```yaml
cache:
key: "$CI_BUILD_REF_NAME"
untracked: true
```
To enable per-job and per-branch caching:
```yaml
cache:
key: "$CI_BUILD_NAME/$CI_BUILD_REF_NAME"
untracked: true
```
To enable per-branch and per-stage caching:
```yaml
cache:
key: "$CI_BUILD_STAGE/$CI_BUILD_REF_NAME"
untracked: true
```
If you use
**Windows Batch**
to run your shell scripts you need to replace the
`$`
with
`%`
:
```yaml
cache:
key: "%CI_BUILD_STAGE%/%CI_BUILD_REF_NAME%"
untracked: true
```
## Jobs
`.gitlab-ci.yml`
allows you to specify an unlimited number of jobs. Each job
...
...
lib/ci/gitlab_ci_yaml_processor.rb
浏览文件 @
c45a6bf3
...
...
@@ -115,6 +115,10 @@ module Ci
end
if
@cache
if
@cache
[
:key
]
&&
!
validate_string
(
@cache
[
:key
])
raise
ValidationError
,
"cache:key parameter should be a string"
end
if
@cache
[
:untracked
]
&&
!
validate_boolean
(
@cache
[
:untracked
])
raise
ValidationError
,
"cache:untracked parameter should be an boolean"
end
...
...
@@ -198,6 +202,10 @@ module Ci
end
def
validate_job_cache!
(
name
,
job
)
if
job
[
:cache
][
:key
]
&&
!
validate_string
(
job
[
:cache
][
:key
])
raise
ValidationError
,
"
#{
name
}
job: cache:key parameter should be a string"
end
if
job
[
:cache
][
:untracked
]
&&
!
validate_boolean
(
job
[
:cache
][
:untracked
])
raise
ValidationError
,
"
#{
name
}
job: cache:untracked parameter should be an boolean"
end
...
...
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
浏览文件 @
c45a6bf3
...
...
@@ -336,7 +336,7 @@ module Ci
describe
"Caches"
do
it
"returns cache when defined globally"
do
config
=
YAML
.
dump
({
cache:
{
paths:
[
"logs/"
,
"binaries/"
],
untracked:
true
},
cache:
{
paths:
[
"logs/"
,
"binaries/"
],
untracked:
true
,
key:
'key'
},
rspec:
{
script:
"rspec"
}
...
...
@@ -348,13 +348,14 @@ module Ci
expect
(
config_processor
.
builds_for_stage_and_ref
(
"test"
,
"master"
).
first
[
:options
][
:cache
]).
to
eq
(
paths:
[
"logs/"
,
"binaries/"
],
untracked:
true
,
key:
'key'
,
)
end
it
"returns cache when defined in a job"
do
config
=
YAML
.
dump
({
rspec:
{
cache:
{
paths:
[
"logs/"
,
"binaries/"
],
untracked:
true
},
cache:
{
paths:
[
"logs/"
,
"binaries/"
],
untracked:
true
,
key:
'key'
},
script:
"rspec"
}
})
...
...
@@ -365,15 +366,16 @@ module Ci
expect
(
config_processor
.
builds_for_stage_and_ref
(
"test"
,
"master"
).
first
[
:options
][
:cache
]).
to
eq
(
paths:
[
"logs/"
,
"binaries/"
],
untracked:
true
,
key:
'key'
,
)
end
it
"overwrite cache when defined for a job and globally"
do
config
=
YAML
.
dump
({
cache:
{
paths:
[
"logs/"
,
"binaries/"
],
untracked:
true
},
cache:
{
paths:
[
"logs/"
,
"binaries/"
],
untracked:
true
,
key:
'global'
},
rspec:
{
script:
"rspec"
,
cache:
{
paths:
[
"test/"
],
untracked:
false
},
cache:
{
paths:
[
"test/"
],
untracked:
false
,
key:
'local'
},
}
})
...
...
@@ -383,6 +385,7 @@ module Ci
expect
(
config_processor
.
builds_for_stage_and_ref
(
"test"
,
"master"
).
first
[
:options
][
:cache
]).
to
eq
(
paths:
[
"test/"
],
untracked:
false
,
key:
'local'
,
)
end
end
...
...
@@ -615,6 +618,20 @@ module Ci
end
.
to
raise_error
(
GitlabCiYamlProcessor
::
ValidationError
,
"cache:paths parameter should be an array of strings"
)
end
it
"returns errors if cache:key is not a string"
do
config
=
YAML
.
dump
({
cache:
{
key:
1
},
rspec:
{
script:
"test"
}
})
expect
do
GitlabCiYamlProcessor
.
new
(
config
)
end
.
to
raise_error
(
GitlabCiYamlProcessor
::
ValidationError
,
"cache:key parameter should be a string"
)
end
it
"returns errors if job cache:key is not an a string"
do
config
=
YAML
.
dump
({
types:
[
"build"
,
"test"
],
rspec:
{
script:
"test"
,
cache:
{
key:
1
}
}
})
expect
do
GitlabCiYamlProcessor
.
new
(
config
)
end
.
to
raise_error
(
GitlabCiYamlProcessor
::
ValidationError
,
"rspec job: cache:key parameter should be a string"
)
end
it
"returns errors if job cache:untracked is not an array of strings"
do
config
=
YAML
.
dump
({
types:
[
"build"
,
"test"
],
rspec:
{
script:
"test"
,
cache:
{
untracked:
"string"
}
}
})
expect
do
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录