Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
a1363d39
Commit
a1363d39
authored
Apr 08, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add `variables` keyword to job in CI config YAML
parent
e32fc756
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
60 additions
and
15 deletions
+60
-15
app/models/ci/build.rb
app/models/ci/build.rb
+10
-2
lib/ci/gitlab_ci_yaml_processor.rb
lib/ci/gitlab_ci_yaml_processor.rb
+2
-1
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
+32
-12
spec/models/build_spec.rb
spec/models/build_spec.rb
+16
-0
No files found.
app/models/ci/build.rb
View file @
a1363d39
...
@@ -365,9 +365,11 @@ module Ci
...
@@ -365,9 +365,11 @@ module Ci
self
.
update
(
erased_by:
user
,
erased_at:
Time
.
now
)
self
.
update
(
erased_by:
user
,
erased_at:
Time
.
now
)
end
end
private
def
yaml_variables
def
yaml_variables
global_yaml_variables
+
job_yaml_variables
end
def
global_yaml_variables
if
commit
.
config_processor
if
commit
.
config_processor
commit
.
config_processor
.
variables
.
map
do
|
key
,
value
|
commit
.
config_processor
.
variables
.
map
do
|
key
,
value
|
{
key:
key
,
value:
value
,
public:
true
}
{
key:
key
,
value:
value
,
public:
true
}
...
@@ -377,6 +379,12 @@ module Ci
...
@@ -377,6 +379,12 @@ module Ci
end
end
end
end
def
job_yaml_variables
options
[
:variables
].
to_h
.
map
do
|
key
,
value
|
{
key:
key
,
value:
value
,
public:
true
}
end
end
def
project_variables
def
project_variables
project
.
variables
.
map
do
|
variable
|
project
.
variables
.
map
do
|
variable
|
{
key:
variable
.
key
,
value:
variable
.
value
,
public:
false
}
{
key:
variable
.
key
,
value:
variable
.
value
,
public:
false
}
...
...
lib/ci/gitlab_ci_yaml_processor.rb
View file @
a1363d39
...
@@ -7,7 +7,7 @@ module Ci
...
@@ -7,7 +7,7 @@ module Ci
ALLOWED_YAML_KEYS
=
[
:before_script
,
:image
,
:services
,
:types
,
:stages
,
:variables
,
:cache
]
ALLOWED_YAML_KEYS
=
[
:before_script
,
:image
,
:services
,
:types
,
:stages
,
:variables
,
:cache
]
ALLOWED_JOB_KEYS
=
[
:tags
,
:script
,
:only
,
:except
,
:type
,
:image
,
:services
,
ALLOWED_JOB_KEYS
=
[
:tags
,
:script
,
:only
,
:except
,
:type
,
:image
,
:services
,
:allow_failure
,
:type
,
:stage
,
:when
,
:artifacts
,
:cache
,
:allow_failure
,
:type
,
:stage
,
:when
,
:artifacts
,
:cache
,
:dependencies
]
:dependencies
,
:variables
]
attr_reader
:before_script
,
:image
,
:services
,
:variables
,
:path
,
:cache
attr_reader
:before_script
,
:image
,
:services
,
:variables
,
:path
,
:cache
...
@@ -85,6 +85,7 @@ module Ci
...
@@ -85,6 +85,7 @@ module Ci
artifacts:
job
[
:artifacts
],
artifacts:
job
[
:artifacts
],
cache:
job
[
:cache
]
||
@cache
,
cache:
job
[
:cache
]
||
@cache
,
dependencies:
job
[
:dependencies
],
dependencies:
job
[
:dependencies
],
variables:
job
[
:variables
],
}.
compact
}.
compact
}
}
end
end
...
...
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
View file @
a1363d39
...
@@ -346,7 +346,8 @@ module Ci
...
@@ -346,7 +346,8 @@ module Ci
end
end
describe
"Variables"
do
describe
"Variables"
do
it
"returns variables when defined"
do
context
'when global variables are defined'
do
it
'returns variables'
do
variables
=
{
variables
=
{
var1:
"value1"
,
var1:
"value1"
,
var2:
"value2"
,
var2:
"value2"
,
...
@@ -362,6 +363,25 @@ module Ci
...
@@ -362,6 +363,25 @@ module Ci
end
end
end
end
context
'when job variables are defined'
do
let
(
:job_variables
)
{
{
KEY1
:
'value1'
,
SOME_KEY_2
:
'value2'
}
}
let
(
:yaml_config
)
do
YAML
.
dump
(
{
before_script:
[
'pwd'
],
rspec:
{
variables:
job_variables
,
script:
'rspec'
}
})
end
it
'appends job variable to job attributes'
do
config
=
GitlabCiYamlProcessor
.
new
(
yaml_config
,
path
)
expect
(
config
.
builds
.
first
[
:options
][
:variables
]).
to
eq
job_variables
end
end
end
describe
"When"
do
describe
"When"
do
%w(on_success on_failure always)
.
each
do
|
when_state
|
%w(on_success on_failure always)
.
each
do
|
when_state
|
it
"returns
#{
when_state
}
when defined"
do
it
"returns
#{
when_state
}
when defined"
do
...
...
spec/models/build_spec.rb
View file @
a1363d39
...
@@ -238,6 +238,22 @@ describe Ci::Build, models: true do
...
@@ -238,6 +238,22 @@ describe Ci::Build, models: true do
it
{
is_expected
.
to
eq
(
predefined_variables
+
predefined_trigger_variable
+
yaml_variables
+
secure_variables
+
trigger_variables
)
}
it
{
is_expected
.
to
eq
(
predefined_variables
+
predefined_trigger_variable
+
yaml_variables
+
secure_variables
+
trigger_variables
)
}
end
end
context
'when job variables are defined'
do
before
{
build
.
update_attribute
(
:options
,
variables:
job_variables
)
}
context
'when job variables are unique'
do
let
(
:job_variables
)
{
{
KEY1
:
'value1'
,
KEY2
:
'value2'
}
}
let
(
:resulting_variables
)
do
[{
key: :KEY1
,
value:
'value1'
,
public:
true
},
{
key: :KEY2
,
value:
'value2'
,
public:
true
}]
end
it
'includes job variables'
do
expect
(
subject
).
to
include
(
*
resulting_variables
)
end
end
end
end
end
end
end
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment