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
Jérome Perrin
gitlab-ce
Commits
bb8bf642
Commit
bb8bf642
authored
Jul 19, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move job environment validation to new CI config
parent
943ae747
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
18 additions
and
20 deletions
+18
-20
lib/ci/gitlab_ci_yaml_processor.rb
lib/ci/gitlab_ci_yaml_processor.rb
+0
-11
lib/gitlab/ci/config/node/job.rb
lib/gitlab/ci/config/node/job.rb
+13
-1
lib/gitlab/ci/config/node/legacy_validation_helpers.rb
lib/gitlab/ci/config/node/legacy_validation_helpers.rb
+0
-4
lib/gitlab/ci/config/node/validators.rb
lib/gitlab/ci/config/node/validators.rb
+2
-1
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
+3
-3
No files found.
lib/ci/gitlab_ci_yaml_processor.rb
View file @
bb8bf642
...
...
@@ -93,21 +93,10 @@ module Ci
def
validate_job!
(
name
,
job
)
raise
ValidationError
,
"Unknown parameter:
#{
name
}
"
unless
job
.
is_a?
(
Hash
)
&&
job
.
has_key?
(
:script
)
validate_job_types!
(
name
,
job
)
validate_job_stage!
(
name
,
job
)
if
job
[
:stage
]
validate_job_dependencies!
(
name
,
job
)
if
job
[
:dependencies
]
end
def
validate_job_types!
(
name
,
job
)
if
job
[
:when
]
&&
!
job
[
:when
].
in?
(
%w[on_success on_failure always]
)
raise
ValidationError
,
"
#{
name
}
job: when parameter should be on_success, on_failure or always"
end
if
job
[
:environment
]
&&
!
validate_environment
(
job
[
:environment
])
raise
ValidationError
,
"
#{
name
}
job: environment parameter
#{
Gitlab
::
Regex
.
environment_name_regex_message
}
"
end
end
def
validate_job_stage!
(
name
,
job
)
unless
job
[
:stage
].
is_a?
(
String
)
&&
job
[
:stage
].
in?
(
@stages
)
raise
ValidationError
,
"
#{
name
}
job: stage parameter should be
#{
@stages
.
join
(
", "
)
}
"
...
...
lib/gitlab/ci/config/node/job.rb
View file @
bb8bf642
...
...
@@ -9,7 +9,7 @@ module Gitlab
include
Configurable
include
Attributable
attributes
:tags
,
:allow_failure
attributes
:tags
,
:allow_failure
,
:when
,
:environment
validations
do
validates
:config
,
allowed_keys:
...
...
@@ -24,6 +24,18 @@ module Gitlab
with_options
allow_nil:
true
do
validates
:tags
,
array_of_strings:
true
validates
:allow_failure
,
boolean:
true
validates
:when
,
inclusion:
{
in:
%w[on_success on_failure always]
,
message:
'should be on_success, on_failure '
\
'or always'
}
validates
:environment
,
type:
{
with:
String
,
message:
Gitlab
::
Regex
.
environment_name_regex_message
}
validates
:environment
,
format:
{
with:
Gitlab
::
Regex
.
environment_name_regex
,
message:
Gitlab
::
Regex
.
environment_name_regex_message
}
end
end
...
...
lib/gitlab/ci/config/node/legacy_validation_helpers.rb
View file @
bb8bf642
...
...
@@ -41,10 +41,6 @@ module Gitlab
false
end
def
validate_environment
(
value
)
value
.
is_a?
(
String
)
&&
value
=~
Gitlab
::
Regex
.
environment_name_regex
end
def
validate_boolean
(
value
)
value
.
in?
([
true
,
false
])
end
...
...
lib/gitlab/ci/config/node/validators.rb
View file @
bb8bf642
...
...
@@ -69,7 +69,8 @@ module Gitlab
raise
unless
type
.
is_a?
(
Class
)
unless
value
.
is_a?
(
type
)
record
.
errors
.
add
(
attribute
,
"should be a
#{
type
.
name
}
"
)
message
=
options
[
:message
]
||
"should be a
#{
type
.
name
}
"
record
.
errors
.
add
(
attribute
,
message
)
end
end
end
...
...
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
View file @
bb8bf642
...
...
@@ -754,7 +754,7 @@ module Ci
let
(
:environment
)
{
1
}
it
'raises error'
do
expect
{
builds
}.
to
raise_error
(
"
deploy_to_production job: environment parameter
#{
Gitlab
::
Regex
.
environment_name_regex_message
}
"
)
expect
{
builds
}.
to
raise_error
(
"
jobs:deploy_to_production environment
#{
Gitlab
::
Regex
.
environment_name_regex_message
}
"
)
end
end
...
...
@@ -762,7 +762,7 @@ module Ci
let
(
:environment
)
{
'production staging'
}
it
'raises error'
do
expect
{
builds
}.
to
raise_error
(
"
deploy_to_production job: environment parameter
#{
Gitlab
::
Regex
.
environment_name_regex_message
}
"
)
expect
{
builds
}.
to
raise_error
(
"
jobs:deploy_to_production environment
#{
Gitlab
::
Regex
.
environment_name_regex_message
}
"
)
end
end
end
...
...
@@ -1131,7 +1131,7 @@ EOT
config
=
YAML
.
dump
({
rspec:
{
script:
"test"
,
when:
1
}
})
expect
do
GitlabCiYamlProcessor
.
new
(
config
,
path
)
end
.
to
raise_error
(
GitlabCiYamlProcessor
::
ValidationError
,
"
rspec job: when parameter
should be on_success, on_failure or always"
)
end
.
to
raise_error
(
GitlabCiYamlProcessor
::
ValidationError
,
"
jobs:rspec when
should be on_success, on_failure or always"
)
end
it
"returns errors if job artifacts:name is not an a string"
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