Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
4f472d49
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,发现更多精彩内容 >>
提交
4f472d49
编写于
2月 27, 2018
作者:
G
Grzegorz Bizon
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make pipeline priority variables concept explicit
上级
83bc2844
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
77 addition
and
14 deletion
+77
-14
app/models/ci/build.rb
app/models/ci/build.rb
+2
-1
app/models/ci/pipeline.rb
app/models/ci/pipeline.rb
+10
-6
app/models/project.rb
app/models/project.rb
+2
-1
spec/models/ci/build_spec.rb
spec/models/ci/build_spec.rb
+26
-0
spec/models/ci/pipeline_spec.rb
spec/models/ci/pipeline_spec.rb
+37
-6
未找到文件。
app/models/ci/build.rb
浏览文件 @
4f472d49
...
...
@@ -262,8 +262,9 @@ module Ci
variables
+=
secret_variables
(
environment:
environment
)
variables
+=
trigger_request
.
user_variables
if
trigger_request
variables
+=
persisted_environment_variables
if
environment
variables
+=
pipeline
.
priority_variables
variables
variables
.
reverse
.
uniq
{
|
variable
|
variable
.
fetch
(
:key
)
}.
reverse
end
def
features
...
...
app/models/ci/pipeline.rb
浏览文件 @
4f472d49
...
...
@@ -473,10 +473,9 @@ module Ci
end
def
predefined_variables
predefined
=
[
p
ipeline_p
redefined
=
[
{
key:
'CI'
,
value:
'true'
,
public:
true
},
{
key:
'GITLAB_CI'
,
value:
'true'
,
public:
true
},
{
key:
'GITLAB_FEATURES'
,
value:
project
.
namespace
.
features
.
join
(
','
),
public:
true
},
{
key:
'CI_SERVER_NAME'
,
value:
'GitLab'
,
public:
true
},
{
key:
'CI_SERVER_VERSION'
,
value:
Gitlab
::
VERSION
,
public:
true
},
{
key:
'CI_SERVER_REVISION'
,
value:
Gitlab
::
REVISION
,
public:
true
},
...
...
@@ -485,11 +484,16 @@ module Ci
{
key:
'CI_PIPELINE_SOURCE'
,
value:
source
.
to_s
,
public:
true
}
]
predefined
+=
project
.
predefined_variables
predefined
+=
pipeline_schedule
.
job_variables
if
pipeline_schedule
predefined
+=
self
.
variables
.
map
(
&
:to_runner_variable
)
Array
(
project
.
predefined_variables
)
+
pipeline_predefined
end
def
priority_variables
Array
(
pipeline_schedule
&
.
job_variables
)
+
self
.
variables
.
map
(
&
:to_runner_variable
)
end
predefined
def
runtime_variables
predefined_variables
+
priority_variables
end
def
queued_duration
...
...
app/models/project.rb
浏览文件 @
4f472d49
...
...
@@ -1589,7 +1589,8 @@ class Project < ActiveRecord::Base
{
key:
'CI_PROJECT_PATH_SLUG'
,
value:
full_path_slug
,
public:
true
},
{
key:
'CI_PROJECT_NAMESPACE'
,
value:
namespace
.
full_path
,
public:
true
},
{
key:
'CI_PROJECT_URL'
,
value:
web_url
,
public:
true
},
{
key:
'CI_PROJECT_VISIBILITY'
,
value:
Gitlab
::
VisibilityLevel
.
string_level
(
visibility_level
),
public:
true
}
{
key:
'CI_PROJECT_VISIBILITY'
,
value:
Gitlab
::
VisibilityLevel
.
string_level
(
visibility_level
),
public:
true
},
{
key:
'GITLAB_FEATURES'
,
value:
namespace
.
features
.
join
(
','
),
public:
true
}
]
variables
+=
container_registry_variables
...
...
spec/models/ci/build_spec.rb
浏览文件 @
4f472d49
...
...
@@ -1891,6 +1891,32 @@ describe Ci::Build do
end
end
end
context
'when there are duplicated variables present '
do
context
'when there are duplicated YAML variables'
do
before
do
build
.
yaml_variables
=
[{
key:
'MYVAR'
,
value:
'first'
,
public:
true
},
{
key:
'MYVAR'
,
value:
'second'
,
public:
true
}]
end
it
'keeps the last occurence of a variable by given key'
do
expect
(
subject
).
not_to
include
(
key:
'MYVAR'
,
value:
'first'
,
public:
true
)
expect
(
subject
).
to
include
(
key:
'MYVAR'
,
value:
'second'
,
public:
true
)
end
end
context
'when pipeline trigger variable overrides YAML variables'
do
before
do
build
.
yaml_variables
=
[{
key:
'MYVAR'
,
value:
'myvar'
,
public:
true
}]
pipeline
.
variables
.
build
(
key:
'MYVAR'
,
value:
'pipeline value'
)
end
it
'overrides YAML variable with a pipeline trigger variable'
do
expect
(
subject
).
not_to
include
(
key:
'MYVAR'
,
value:
'myvar'
,
public:
true
)
expect
(
subject
).
to
include
(
key:
'MYVAR'
,
value:
'pipeline value'
,
public:
false
)
end
end
end
end
describe
'state transition: any => [:pending]'
do
...
...
spec/models/ci/pipeline_spec.rb
浏览文件 @
4f472d49
...
...
@@ -167,15 +167,46 @@ describe Ci::Pipeline, :mailer do
end
end
describe
'#predefined_variables'
do
subject
{
pipeline
.
predefined_variables
}
describe
'pipeline variables'
do
describe
'#predefined_variables'
do
subject
{
pipeline
.
predefined_variables
}
it
{
is_expected
.
to
be_an
(
Array
)
}
it
{
is_expected
.
to
be_an
(
Array
)
}
it
'includes the defined keys'
do
keys
=
subject
.
map
{
|
v
|
v
.
fetch
(
:key
)
}
expect
(
keys
).
to
include
(
'CI_PIPELINE_ID'
,
'CI_CONFIG_PATH'
,
'CI_PIPELINE_SOURCE'
)
end
it
'includes project-level predefined variables'
do
keys
=
subject
.
map
{
|
v
|
v
.
fetch
(
:key
)
}
expect
(
keys
).
to
include
(
'CI_PROJECT_NAME'
)
end
end
describe
'#priority_variables'
do
before
do
pipeline
.
variables
.
build
(
key:
'MY_VAR'
,
value:
'my var'
)
end
it
'includes the defined keys'
do
keys
=
subject
.
map
{
|
v
|
v
[
:key
]
}
it
'returns trigger variables'
do
expect
(
pipeline
.
priority_variables
)
.
to
include
(
key:
'MY_VAR'
,
value:
'my var'
,
public:
false
)
end
end
expect
(
keys
).
to
include
(
'CI_PIPELINE_ID'
,
'CI_CONFIG_PATH'
,
'CI_PIPELINE_SOURCE'
)
describe
'#runtime_variables'
do
before
do
pipeline
.
variables
.
build
(
key:
'MY_VAR'
,
value:
'my var'
)
end
it
'includes predefined and priority variables'
do
variables
=
pipeline
.
runtime_variables
.
map
{
|
v
|
v
.
fetch
(
:key
)
}
expect
(
variables
).
to
include
(
'MY_VAR'
,
'CI_PIPELINE_ID'
,
'CI_PROJECT_ID'
)
end
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录