Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
ad4d3a07
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,发现更多精彩内容 >>
提交
ad4d3a07
编写于
3月 11, 2016
作者:
K
Kamil Trzcinski
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Describe special YAML features: the use of anchors and hidden jobs
上级
0c5b92cb
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
104 addition
and
0 deletion
+104
-0
CHANGELOG
CHANGELOG
+2
-0
doc/ci/yaml/README.md
doc/ci/yaml/README.md
+71
-0
lib/ci/gitlab_ci_yaml_processor.rb
lib/ci/gitlab_ci_yaml_processor.rb
+2
-0
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
+29
-0
未找到文件。
CHANGELOG
浏览文件 @
ad4d3a07
...
...
@@ -16,6 +16,8 @@ v 8.6.0 (unreleased)
- Return empty array instead of 404 when commit has no statuses in commit status API
- Decrease the font size and the padding of the `.anchor` icons used in the README (Roberto Dip)
- Rewrite logo to simplify SVG code (Sean Lang)
- Allow to use YAML anchors when parsing the `.gitlab-ci.yml` (Pascal Bach)
- Ignore jobs that start with `.` (hidden jobs)
- Add support for cross-project label references
- Update documentation to reflect Guest role not being enforced on internal projects
- Allow search for logged out users
...
...
doc/ci/yaml/README.md
浏览文件 @
ad4d3a07
...
...
@@ -509,6 +509,77 @@ rspec:
The cache is provided on best effort basis, so don't expect that cache will be
always present. For implementation details please check GitLab Runner.
## Special features
It's possible special YAML features like anchors and map merging.
Thus allowing to greatly reduce the complexity of
`.gitlab-ci.yml`
.
#### Anchors
You can read more about YAML features
[
here
](
https://learnxinyminutes.com/docs/yaml/
)
.
```
yaml
.job_template
:
&job_definition
image
:
ruby:2.1
services
:
-
postgres
-
redis
test1
:
<< *job_definition
script
:
-
test project
test2
:
<< *job_definition
script
:
-
test project
```
The above example uses anchors and map merging.
It will create a two jobs:
`test1`
and
`test2`
that will have the parameters of
`.job_template`
and custom
`script`
defined.
```
yaml
.job_template
:
&job_definition
script
:
-
test project
.postgres_services
:
services
:
&postgres_definition
-
postgres
-
ruby
.mysql_services
:
services
:
&mysql_definition
-
mysql
-
ruby
test:postgres:
<< *job_definition
services
:
*postgres_definition
test:mysql:
<< *job_definition
services
:
*mysql_definition
```
The above example uses anchors to define two set of services.
It will create a two jobs:
`test:postgres`
and
`test:mysql`
that will have the script defined in
`.job_template`
and one, the service defined in
`.postgres_services`
and second the services defined in
`.mysql_services`
.
### Hidden jobs
The jobs that start with
`.`
will be not processed by GitLab.
Example of such hidden jobs:
```
yaml
.job_name
:
script
:
-
rake spec
```
The
`.job_name`
will be ignored. You can use this feature to ignore jobs, or use them as templates with special YAML features.
## Validate the .gitlab-ci.yml
Each instance of GitLab CI has an embedded debug tool called Lint.
...
...
lib/ci/gitlab_ci_yaml_processor.rb
浏览文件 @
ad4d3a07
...
...
@@ -60,6 +60,7 @@ module Ci
@jobs
=
{}
@config
.
each
do
|
key
,
job
|
next
if
key
.
to_s
.
start_with?
(
'.'
)
stage
=
job
[
:stage
]
||
job
[
:type
]
||
DEFAULT_STAGE
@jobs
[
key
]
=
{
stage:
stage
}.
merge
(
job
)
end
...
...
@@ -81,6 +82,7 @@ module Ci
services:
job
[
:services
]
||
@services
,
artifacts:
job
[
:artifacts
],
cache:
job
[
:cache
]
||
@cache
,
dependencies:
job
[
:dependencies
],
}.
compact
}
end
...
...
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
浏览文件 @
ad4d3a07
...
...
@@ -427,6 +427,35 @@ module Ci
end
end
describe
"Hidden jobs"
do
let
(
:config
)
do
YAML
.
dump
({
'.hidden_job'
=>
{
script:
'test'
},
'normal_job'
=>
{
script:
'test'
}
})
end
let
(
:config_processor
)
{
GitlabCiYamlProcessor
.
new
(
config
)
}
subject
{
config_processor
.
builds_for_stage_and_ref
(
"test"
,
"master"
)
}
it
"doesn't create jobs that starts with dot"
do
expect
(
subject
.
size
).
to
eq
(
1
)
expect
(
subject
.
first
).
to
eq
({
except:
nil
,
stage:
"test"
,
stage_idx:
1
,
name: :normal_job
,
only:
nil
,
commands:
"
\n
test"
,
tag_list:
[],
options:
{},
when:
"on_success"
,
allow_failure:
false
})
end
end
describe
"Error handling"
do
it
"fails to parse YAML"
do
expect
{
GitlabCiYamlProcessor
.
new
(
"invalid: yaml: test"
)}.
to
raise_error
(
Psych
::
SyntaxError
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录