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
iv
gitlab-ce
Commits
2305483d
Commit
2305483d
authored
Oct 22, 2015
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Require jobs to be named
parent
8b127f45
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
15 deletions
+38
-15
CHANGELOG
CHANGELOG
+1
-0
lib/ci/gitlab_ci_yaml_processor.rb
lib/ci/gitlab_ci_yaml_processor.rb
+23
-15
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
+14
-0
No files found.
CHANGELOG
View file @
2305483d
...
...
@@ -20,6 +20,7 @@ v 8.1.0 (unreleased)
- Don't show "Add README" link in an empty repository if user doesn't have access to push (Stan Hu)
- Fix error preventing displaying of commit data for a directory with a leading dot (Stan Hu)
- Speed up load times of issue detail pages by roughly 1.5x
- Require CI jobs to be named
- If a merge request is to close an issue, show this on the issue page (Zeger-Jan van de Weg)
- Add a system note and update relevant merge requests when a branch is deleted or re-added (Stan Hu)
- Make diff file view easier to use on mobile screens (Stan Hu)
...
...
lib/ci/gitlab_ci_yaml_processor.rb
View file @
2305483d
...
...
@@ -139,66 +139,74 @@ module Ci
end
@jobs
.
each
do
|
name
,
job
|
validate_job!
(
"
#{
name
}
job"
,
job
)
validate_job!
(
name
,
job
)
end
true
end
def
validate_job!
(
name
,
job
)
if
name
.
blank?
||
!
validate_string
(
name
)
raise
ValidationError
,
"job name should be non-empty string"
end
job
.
keys
.
each
do
|
key
|
unless
ALLOWED_JOB_KEYS
.
include?
key
raise
ValidationError
,
"
#{
name
}
: unknown parameter
#{
key
}
"
raise
ValidationError
,
"
#{
name
}
job
: unknown parameter
#{
key
}
"
end
end
if
!
job
[
:script
].
is_a?
(
String
)
&&
!
validate_array_of_strings
(
job
[
:script
])
raise
ValidationError
,
"
#{
name
}
: script should be a string or an array of a strings"
if
!
validate_string
(
job
[
:script
]
)
&&
!
validate_array_of_strings
(
job
[
:script
])
raise
ValidationError
,
"
#{
name
}
job
: script should be a string or an array of a strings"
end
if
job
[
:stage
]
unless
job
[
:stage
].
is_a?
(
String
)
&&
job
[
:stage
].
in?
(
stages
)
raise
ValidationError
,
"
#{
name
}
: stage parameter should be
#{
stages
.
join
(
", "
)
}
"
raise
ValidationError
,
"
#{
name
}
job
: stage parameter should be
#{
stages
.
join
(
", "
)
}
"
end
end
if
job
[
:image
]
&&
!
job
[
:image
].
is_a?
(
String
)
raise
ValidationError
,
"
#{
name
}
: image should be a string"
if
job
[
:image
]
&&
!
validate_string
(
job
[
:image
]
)
raise
ValidationError
,
"
#{
name
}
job
: image should be a string"
end
if
job
[
:services
]
&&
!
validate_array_of_strings
(
job
[
:services
])
raise
ValidationError
,
"
#{
name
}
: services should be an array of strings"
raise
ValidationError
,
"
#{
name
}
job
: services should be an array of strings"
end
if
job
[
:tags
]
&&
!
validate_array_of_strings
(
job
[
:tags
])
raise
ValidationError
,
"
#{
name
}
: tags parameter should be an array of strings"
raise
ValidationError
,
"
#{
name
}
job
: tags parameter should be an array of strings"
end
if
job
[
:only
]
&&
!
validate_array_of_strings
(
job
[
:only
])
raise
ValidationError
,
"
#{
name
}
: only parameter should be an array of strings"
raise
ValidationError
,
"
#{
name
}
job
: only parameter should be an array of strings"
end
if
job
[
:except
]
&&
!
validate_array_of_strings
(
job
[
:except
])
raise
ValidationError
,
"
#{
name
}
: except parameter should be an array of strings"
raise
ValidationError
,
"
#{
name
}
job
: except parameter should be an array of strings"
end
if
job
[
:allow_failure
]
&&
!
job
[
:allow_failure
].
in?
([
true
,
false
])
raise
ValidationError
,
"
#{
name
}
: allow_failure parameter should be an boolean"
raise
ValidationError
,
"
#{
name
}
job
: allow_failure parameter should be an boolean"
end
if
job
[
:when
]
&&
!
job
[
:when
].
in?
(
%w(on_success on_failure always)
)
raise
ValidationError
,
"
#{
name
}
: when parameter should be on_success, on_failure or always"
raise
ValidationError
,
"
#{
name
}
job
: when parameter should be on_success, on_failure or always"
end
end
private
def
validate_array_of_strings
(
values
)
values
.
is_a?
(
Array
)
&&
values
.
all?
{
|
tag
|
tag
.
is_a?
(
String
)
}
values
.
is_a?
(
Array
)
&&
values
.
all?
{
|
value
|
validate_string
(
value
)
}
end
def
validate_variables
(
variables
)
variables
.
is_a?
(
Hash
)
&&
variables
.
all?
{
|
key
,
value
|
key
.
is_a?
(
Symbol
)
&&
value
.
is_a?
(
String
)}
variables
.
is_a?
(
Hash
)
&&
variables
.
all?
{
|
key
,
value
|
validate_string
(
key
)
&&
validate_string
(
value
)
}
end
def
validate_string
(
value
)
value
.
is_a?
(
String
)
||
value
.
is_a?
(
Symbol
)
end
end
end
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
View file @
2305483d
...
...
@@ -218,6 +218,20 @@ module Ci
end
.
to
raise_error
(
GitlabCiYamlProcessor
::
ValidationError
,
"image should be a string"
)
end
it
"returns errors if job name is blank"
do
config
=
YAML
.
dump
({
''
=>
{
script:
"test"
}
})
expect
do
GitlabCiYamlProcessor
.
new
(
config
)
end
.
to
raise_error
(
GitlabCiYamlProcessor
::
ValidationError
,
"job name should be non-empty string"
)
end
it
"returns errors if job name is non-string"
do
config
=
YAML
.
dump
({
10
=>
{
script:
"test"
}
})
expect
do
GitlabCiYamlProcessor
.
new
(
config
)
end
.
to
raise_error
(
GitlabCiYamlProcessor
::
ValidationError
,
"job name should be non-empty string"
)
end
it
"returns errors if job image parameter is invalid"
do
config
=
YAML
.
dump
({
rspec:
{
script:
"test"
,
image:
[
"test"
]
}
})
expect
do
...
...
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