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
Tatuya Kamada
gitlab-ce
Commits
ad859287
Commit
ad859287
authored
Oct 18, 2016
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add logical validation to gitlab-ci.yml
parent
0aa23270
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
77 additions
and
1 deletion
+77
-1
app/controllers/projects/environments_controller.rb
app/controllers/projects/environments_controller.rb
+1
-1
lib/ci/gitlab_ci_yaml_processor.rb
lib/ci/gitlab_ci_yaml_processor.rb
+30
-0
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
+46
-0
No files found.
app/controllers/projects/environments_controller.rb
View file @
ad859287
...
...
@@ -10,7 +10,7 @@ class Projects::EnvironmentsController < Projects::ApplicationController
@scope
=
params
[
:scope
]
@all_environments
=
project
.
environments
@environments
=
if
@scope
==
'stopped'
then
if
@scope
==
'stopped'
@all_environments
.
stopped
else
@all_environments
.
available
...
...
lib/ci/gitlab_ci_yaml_processor.rb
View file @
ad859287
...
...
@@ -109,6 +109,7 @@ module Ci
validate_job_stage!
(
name
,
job
)
validate_job_dependencies!
(
name
,
job
)
validate_job_environment!
(
name
,
job
)
end
end
...
...
@@ -150,6 +151,35 @@ module Ci
end
end
def
validate_job_environment!
(
name
,
job
)
return
unless
job
[
:environment
]
return
unless
job
[
:environment
].
is_a?
(
Hash
)
environment
=
job
[
:environment
]
validate_on_stop_job!
(
name
,
environment
,
environment
[
:on_stop
])
end
def
validate_on_stop_job!
(
name
,
environment
,
on_stop
)
return
unless
on_stop
on_stop_job
=
@jobs
[
on_stop
.
to_sym
]
unless
on_stop_job
raise
ValidationError
,
"
#{
name
}
job: on_stop job
#{
on_stop
}
is not defined"
end
unless
on_stop_job
[
:environment
]
raise
ValidationError
,
"
#{
name
}
job: on_stop job
#{
on_stop
}
does not have environment defined"
end
unless
on_stop_job
[
:environment
][
:name
]
==
environment
[
:name
]
raise
ValidationError
,
"
#{
name
}
job: on_stop job
#{
on_stop
}
have different environment name"
end
unless
on_stop_job
[
:environment
][
:action
]
==
'stop'
raise
ValidationError
,
"
#{
name
}
job: on_stop job
#{
on_stop
}
needs to have action stop defined"
end
end
def
process?
(
only_params
,
except_params
,
ref
,
tag
,
trigger_request
)
if
only_params
.
present?
return
false
unless
matching?
(
only_params
,
ref
,
tag
,
trigger_request
)
...
...
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
View file @
ad859287
...
...
@@ -796,6 +796,52 @@ module Ci
expect
{
builds
}.
to
raise_error
(
"jobs:deploy_to_production:environment name
#{
Gitlab
::
Regex
.
environment_name_regex_message
}
"
)
end
end
context
'when on_stop is specified'
do
let
(
:review
)
{
{
stage:
'deploy'
,
script:
'test'
,
environment:
{
name:
'review'
,
on_stop:
'close_review'
}
}
}
let
(
:config
)
{
{
review:
review
,
close_review:
close_review
}.
compact
}
context
'with matching job'
do
let
(
:close_review
)
{
{
stage:
'deploy'
,
script:
'test'
,
environment:
{
name:
'review'
,
action:
'stop'
}
}
}
it
'does return a list of builds'
do
expect
(
builds
.
size
).
to
eq
(
2
)
expect
(
builds
.
first
[
:environment
]).
to
eq
(
'review'
)
end
end
context
'without matching job'
do
let
(
:close_review
)
{
nil
}
it
'raises error'
do
expect
{
builds
}.
to
raise_error
(
'review job: on_stop job close_review is not defined'
)
end
end
context
'with close job without environment'
do
let
(
:close_review
)
{
{
stage:
'deploy'
,
script:
'test'
}
}
it
'raises error'
do
expect
{
builds
}.
to
raise_error
(
'review job: on_stop job close_review does not have environment defined'
)
end
end
context
'with close job for different environment'
do
let
(
:close_review
)
{
{
stage:
'deploy'
,
script:
'test'
,
environment:
'production'
}
}
it
'raises error'
do
expect
{
builds
}.
to
raise_error
(
'review job: on_stop job close_review have different environment name'
)
end
end
context
'with close job without stop action'
do
let
(
:close_review
)
{
{
stage:
'deploy'
,
script:
'test'
,
environment:
{
name:
'review'
}
}
}
it
'raises error'
do
expect
{
builds
}.
to
raise_error
(
'review job: on_stop job close_review needs to have action stop defined'
)
end
end
end
end
describe
"Dependencies"
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