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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
2b1c08be
Commit
2b1c08be
authored
Apr 17, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Validate job-level variables in YAML config file
parent
a2957291
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
13 deletions
+40
-13
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
+32
-13
No files found.
lib/ci/gitlab_ci_yaml_processor.rb
View file @
2b1c08be
...
...
@@ -153,6 +153,7 @@ module Ci
validate_job_types!
(
name
,
job
)
validate_job_stage!
(
name
,
job
)
if
job
[
:stage
]
validate_job_variables!
(
name
,
job
)
if
job
[
:variables
]
validate_job_cache!
(
name
,
job
)
if
job
[
:cache
]
validate_job_artifacts!
(
name
,
job
)
if
job
[
:artifacts
]
validate_job_dependencies!
(
name
,
job
)
if
job
[
:dependencies
]
...
...
@@ -214,6 +215,13 @@ module Ci
end
end
def
validate_job_variables!
(
name
,
job
)
if
job
[
:variables
]
&&
!
validate_variables
(
job
[
:variables
])
raise
ValidationError
,
"
#{
name
}
job: variables should be a map of key-valued strings"
end
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"
...
...
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
View file @
2b1c08be
...
...
@@ -366,22 +366,41 @@ module Ci
end
context
'when job variables are defined'
do
it
'returns job variables'
do
variables
=
{
KEY1
:
'value1'
,
SOME_KEY_2
:
'value2'
}
context
'when syntax is correct'
do
it
'returns job variables'
do
variables
=
{
KEY1
:
'value1'
,
SOME_KEY_2
:
'value2'
}
config
=
YAML
.
dump
(
{
before_script:
[
'pwd'
],
rspec:
{
variables:
variables
,
script:
'rspec'
}
})
config
=
YAML
.
dump
(
{
before_script:
[
'pwd'
],
rspec:
{
variables:
variables
,
script:
'rspec'
}
})
config_processor
=
GitlabCiYamlProcessor
.
new
(
config
,
path
)
config_processor
=
GitlabCiYamlProcessor
.
new
(
config
,
path
)
expect
(
config_processor
.
job_variables
(
:rspec
)).
to
eq
variables
end
end
expect
(
config_processor
.
job_variables
(
:rspec
)).
to
eq
variables
context
'when syntax is incorrect'
do
it
'raises error'
do
variables
=
[
:KEY1
,
'value1'
,
:KEY2
,
'value2'
]
config
=
YAML
.
dump
(
{
before_script:
[
'pwd'
],
rspec:
{
variables:
variables
,
script:
'rspec'
}
})
expect
{
GitlabCiYamlProcessor
.
new
(
config
,
path
)
}
.
to
raise_error
(
GitlabCiYamlProcessor
::
ValidationError
,
/job: variables should be a map/
)
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