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
4cc9a02e
Commit
4cc9a02e
authored
Apr 16, 2016
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow the before_script and finally_script to be overwritten in context of job
parent
b340b597
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
81 additions
and
14 deletions
+81
-14
lib/ci/gitlab_ci_yaml_processor.rb
lib/ci/gitlab_ci_yaml_processor.rb
+11
-11
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
+70
-3
No files found.
lib/ci/gitlab_ci_yaml_processor.rb
View file @
4cc9a02e
...
...
@@ -7,7 +7,7 @@ module Ci
ALLOWED_YAML_KEYS
=
[
:before_script
,
:finally_script
,
:image
,
:services
,
:types
,
:stages
,
:variables
,
:cache
]
ALLOWED_JOB_KEYS
=
[
:tags
,
:script
,
:only
,
:except
,
:type
,
:image
,
:services
,
:allow_failure
,
:type
,
:stage
,
:when
,
:artifacts
,
:cache
,
:dependencies
]
:dependencies
,
:before_script
,
:finally_script
]
attr_reader
:before_script
,
:finally_script
,
:image
,
:services
,
:variables
,
:path
,
:cache
...
...
@@ -73,7 +73,7 @@ module Ci
{
stage_idx:
stages
.
index
(
job
[
:stage
]),
stage:
job
[
:stage
],
commands:
"
#{
@before_script
.
join
(
"
\n
"
)
}
\n
#{
normalize_script
(
job
[
:script
])
}
"
,
commands:
[
job
[
:before_script
]
||
@before_script
,
job
[
:script
]].
flatten
.
join
(
"
\n
"
)
,
tag_list:
job
[
:tags
]
||
[],
name:
name
,
only:
job
[
:only
],
...
...
@@ -86,19 +86,11 @@ module Ci
artifacts:
job
[
:artifacts
],
cache:
job
[
:cache
]
||
@cache
,
dependencies:
job
[
:dependencies
],
finally_script:
@finally_script
,
finally_script:
job
[
:finally_script
]
||
@finally_script
,
}.
compact
}
end
def
normalize_script
(
script
)
if
script
.
is_a?
Array
script
.
join
(
"
\n
"
)
else
script
end
end
def
validate!
unless
validate_array_of_strings
(
@before_script
)
raise
ValidationError
,
"before_script should be an array of strings"
...
...
@@ -177,6 +169,14 @@ module Ci
raise
ValidationError
,
"
#{
name
}
job: script should be a string or an array of a strings"
end
if
job
[
:before_script
]
&&
!
validate_array_of_strings
(
job
[
:before_script
])
raise
ValidationError
,
"
#{
name
}
job: before_script should be an array of strings"
end
if
job
[
:finally_script
]
&&
!
validate_array_of_strings
(
job
[
:finally_script
])
raise
ValidationError
,
"
#{
name
}
job: finally_script should be an array of strings"
end
if
job
[
:image
]
&&
!
validate_string
(
job
[
:image
])
raise
ValidationError
,
"
#{
name
}
job: image should be a string"
end
...
...
spec/lib/ci/gitlab_ci_yaml_processor_spec.rb
View file @
4cc9a02e
...
...
@@ -293,6 +293,46 @@ module Ci
subject
{
config_processor
.
builds_for_stage_and_ref
(
"test"
,
"master"
).
first
}
describe
"before_script"
do
context
"in global context"
do
let
(
:config
)
{
{
before_script:
[
"global script"
],
test:
{
script:
[
"script"
]
}
}
}
it
"return commands with scripts concencaced"
do
expect
(
subject
[
:commands
]).
to
eq
(
"global script
\n
script"
)
end
end
context
"overwritten in local context"
do
let
(
:config
)
{
{
before_script:
[
"global script"
],
test:
{
before_script:
[
"local script"
],
script:
[
"script"
]
}
}
}
it
"return commands with scripts concencaced"
do
expect
(
subject
[
:commands
]).
to
eq
(
"local script
\n
script"
)
end
end
end
describe
"script"
do
let
(
:config
)
{
{
test:
{
script:
[
"script"
]
}
}
}
it
"return commands with scripts concencaced"
do
expect
(
subject
[
:commands
]).
to
eq
(
"script"
)
end
end
describe
"finally_script"
do
context
"in global context"
do
let
(
:config
)
{
...
...
@@ -306,6 +346,19 @@ module Ci
expect
(
subject
[
:options
][
:finally_script
]).
to
eq
([
"finally_script"
])
end
end
context
"overwritten in local context"
do
let
(
:config
)
{
{
finally_script:
[
"local finally_script"
],
test:
{
finally_script:
[
"local finally_script"
],
script:
[
"script"
]
}
}
}
it
"return finally_script in options"
do
expect
(
subject
[
:options
][
:finally_script
]).
to
eq
([
"local finally_script"
])
end
end
end
end
...
...
@@ -558,7 +611,7 @@ module Ci
stage_idx:
1
,
name: :normal_job
,
only:
nil
,
commands:
"
\n
test"
,
commands:
"test"
,
tag_list:
[],
options:
{},
when:
"on_success"
,
...
...
@@ -585,7 +638,7 @@ EOT
stage_idx:
1
,
name: :job1
,
only:
nil
,
commands:
"
\n
execute-script-for-job"
,
commands:
"execute-script-for-job"
,
tag_list:
[],
options:
{},
when:
"on_success"
,
...
...
@@ -597,7 +650,7 @@ EOT
stage_idx:
1
,
name: :job2
,
only:
nil
,
commands:
"
\n
execute-script-for-job"
,
commands:
"execute-script-for-job"
,
tag_list:
[],
options:
{},
when:
"on_success"
,
...
...
@@ -629,6 +682,13 @@ EOT
end
.
to
raise_error
(
GitlabCiYamlProcessor
::
ValidationError
,
"before_script should be an array of strings"
)
end
it
"returns errors if job before_script parameter is not an array of strings"
do
config
=
YAML
.
dump
({
rspec:
{
script:
"test"
,
before_script:
[
10
,
"test"
]
}
})
expect
do
GitlabCiYamlProcessor
.
new
(
config
,
path
)
end
.
to
raise_error
(
GitlabCiYamlProcessor
::
ValidationError
,
"rspec job: before_script should be an array of strings"
)
end
it
"returns errors if finally_script parameter is invalid"
do
config
=
YAML
.
dump
({
finally_script:
"bundle update"
,
rspec:
{
script:
"test"
}
})
expect
do
...
...
@@ -636,6 +696,13 @@ EOT
end
.
to
raise_error
(
GitlabCiYamlProcessor
::
ValidationError
,
"finally_script should be an array of strings"
)
end
it
"returns errors if job finally_script parameter is not an array of strings"
do
config
=
YAML
.
dump
({
rspec:
{
script:
"test"
,
finally_script:
[
10
,
"test"
]
}
})
expect
do
GitlabCiYamlProcessor
.
new
(
config
,
path
)
end
.
to
raise_error
(
GitlabCiYamlProcessor
::
ValidationError
,
"rspec job: finally_script should be an array of strings"
)
end
it
"returns errors if image parameter is invalid"
do
config
=
YAML
.
dump
({
image:
[
"test"
],
rspec:
{
script:
"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