BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
b340b597
Commit
b340b597
authored
Apr 16, 2016
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement finally_script which allows to do cleanups as part of the build process
parent
8c9cc6d2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
2 deletions
+37
-2
gitlab_ci_yaml_processor.rb
lib/ci/gitlab_ci_yaml_processor.rb
+8
-2
gitlab_ci_yaml_processor_spec.rb
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
+29
-0
No files found.
lib/ci/gitlab_ci_yaml_processor.rb
View file @
b340b597
...
@@ -4,12 +4,12 @@ module Ci
...
@@ -4,12 +4,12 @@ module Ci
DEFAULT_STAGES
=
%w(build test deploy)
DEFAULT_STAGES
=
%w(build test deploy)
DEFAULT_STAGE
=
'test'
DEFAULT_STAGE
=
'test'
ALLOWED_YAML_KEYS
=
[
:before_script
,
:image
,
:services
,
:types
,
:stages
,
:variables
,
:cache
]
ALLOWED_YAML_KEYS
=
[
:before_script
,
:
finally_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
]
attr_reader
:before_script
,
:image
,
:services
,
:variables
,
:path
,
:cache
attr_reader
:before_script
,
:
finally_script
,
:
image
,
:services
,
:variables
,
:path
,
:cache
def
initialize
(
config
,
path
=
nil
)
def
initialize
(
config
,
path
=
nil
)
@config
=
YAML
.
safe_load
(
config
,
[
Symbol
],
[],
true
)
@config
=
YAML
.
safe_load
(
config
,
[
Symbol
],
[],
true
)
...
@@ -44,6 +44,7 @@ module Ci
...
@@ -44,6 +44,7 @@ module Ci
def
initial_parsing
def
initial_parsing
@before_script
=
@config
[
:before_script
]
||
[]
@before_script
=
@config
[
:before_script
]
||
[]
@finally_script
=
@config
[
:finally_script
]
@image
=
@config
[
:image
]
@image
=
@config
[
:image
]
@services
=
@config
[
:services
]
@services
=
@config
[
:services
]
@stages
=
@config
[
:stages
]
||
@config
[
:types
]
@stages
=
@config
[
:stages
]
||
@config
[
:types
]
...
@@ -85,6 +86,7 @@ module Ci
...
@@ -85,6 +86,7 @@ module Ci
artifacts:
job
[
:artifacts
],
artifacts:
job
[
:artifacts
],
cache:
job
[
:cache
]
||
@cache
,
cache:
job
[
:cache
]
||
@cache
,
dependencies:
job
[
:dependencies
],
dependencies:
job
[
:dependencies
],
finally_script:
@finally_script
,
}.
compact
}.
compact
}
}
end
end
...
@@ -102,6 +104,10 @@ module Ci
...
@@ -102,6 +104,10 @@ module Ci
raise
ValidationError
,
"before_script should be an array of strings"
raise
ValidationError
,
"before_script should be an array of strings"
end
end
unless
@finally_script
.
nil?
||
validate_array_of_strings
(
@finally_script
)
raise
ValidationError
,
"finally_script should be an array of strings"
end
unless
@image
.
nil?
||
@image
.
is_a?
(
String
)
unless
@image
.
nil?
||
@image
.
is_a?
(
String
)
raise
ValidationError
,
"image should be a string"
raise
ValidationError
,
"image should be a string"
end
end
...
...
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
View file @
b340b597
...
@@ -287,6 +287,28 @@ module Ci
...
@@ -287,6 +287,28 @@ module Ci
end
end
describe
"Scripts handling"
do
let
(
:config_data
)
{
YAML
.
dump
(
config
)
}
let
(
:config_processor
)
{
GitlabCiYamlProcessor
.
new
(
config_data
,
path
)
}
subject
{
config_processor
.
builds_for_stage_and_ref
(
"test"
,
"master"
).
first
}
describe
"finally_script"
do
context
"in global context"
do
let
(
:config
)
{
{
finally_script:
[
"finally_script"
],
test:
{
script:
[
"script"
]
}
}
}
it
"return finally_script in options"
do
expect
(
subject
[
:options
][
:finally_script
]).
to
eq
([
"finally_script"
])
end
end
end
end
describe
"Image and service handling"
do
describe
"Image and service handling"
do
it
"returns image and service when defined"
do
it
"returns image and service when defined"
do
config
=
YAML
.
dump
({
config
=
YAML
.
dump
({
...
@@ -607,6 +629,13 @@ EOT
...
@@ -607,6 +629,13 @@ EOT
end
.
to
raise_error
(
GitlabCiYamlProcessor
::
ValidationError
,
"before_script should be an array of strings"
)
end
.
to
raise_error
(
GitlabCiYamlProcessor
::
ValidationError
,
"before_script should be an array of strings"
)
end
end
it
"returns errors if finally_script parameter is invalid"
do
config
=
YAML
.
dump
({
finally_script:
"bundle update"
,
rspec:
{
script:
"test"
}
})
expect
do
GitlabCiYamlProcessor
.
new
(
config
,
path
)
end
.
to
raise_error
(
GitlabCiYamlProcessor
::
ValidationError
,
"finally_script should be an array of strings"
)
end
it
"returns errors if image parameter is invalid"
do
it
"returns errors if image parameter is invalid"
do
config
=
YAML
.
dump
({
image:
[
"test"
],
rspec:
{
script:
"test"
}
})
config
=
YAML
.
dump
({
image:
[
"test"
],
rspec:
{
script:
"test"
}
})
expect
do
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