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
6920390a
Commit
6920390a
authored
Jul 13, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add before script and commands to CI job entry
parent
097550f0
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
124 additions
and
8 deletions
+124
-8
lib/gitlab/ci/config/node/job.rb
lib/gitlab/ci/config/node/job.rb
+13
-2
spec/lib/gitlab/ci/config/node/job_spec.rb
spec/lib/gitlab/ci/config/node/job_spec.rb
+111
-6
No files found.
lib/gitlab/ci/config/node/job.rb
View file @
6920390a
...
...
@@ -10,6 +10,7 @@ module Gitlab
validations
do
validates
:config
,
presence:
true
validates
:global
,
required:
true
,
on: :processed
end
node
:before_script
,
Script
,
...
...
@@ -30,8 +31,6 @@ module Gitlab
helpers
:before_script
,
:script
,
:stage
,
:type
,
:after_script
def
value
raise
InvalidError
unless
valid?
##
# TODO, refactoring step: do not expose internal configuration,
# return only hash value without merging it to internal config.
...
...
@@ -39,6 +38,18 @@ module Gitlab
@config
.
merge
(
to_hash
.
compact
)
end
def
before_script
if
before_script_defined?
before_script_value
.
to_a
else
@global
.
before_script
.
to_a
end
end
def
commands
(
before_script
+
script
).
join
(
"
\n
"
)
end
private
def
to_hash
...
...
spec/lib/gitlab/ci/config/node/job_spec.rb
View file @
6920390a
...
...
@@ -60,14 +60,62 @@ describe Gitlab::Ci::Config::Node::Job do
after_script:
%w[cleanup]
)
end
end
end
context
'when entry is incorrect'
do
let
(
:config
)
{
{}
}
describe
'#before_script'
do
context
'when global entry has before script'
do
before
do
allow
(
global
).
to
receive
(
:before_script
)
.
and_return
(
%w[ls pwd]
)
end
context
'when before script is overridden'
do
let
(
:config
)
do
{
before_script:
%w[whoami]
,
script:
'rspec'
}
end
it
'returns correct script'
do
expect
(
entry
.
before_script
).
to
eq
%w[whoami]
end
end
context
'when before script is not overriden'
do
let
(
:config
)
do
{
script:
%w[spinach]
}
end
it
'raises error'
do
expect
{
entry
.
value
}.
to
raise_error
(
Gitlab
::
Ci
::
Config
::
Node
::
Entry
::
InvalidError
)
it
'returns correct script'
do
expect
(
entry
.
before_script
).
to
eq
%w[ls pwd]
end
end
end
context
'when global entry does not have before script'
do
before
do
allow
(
global
).
to
receive
(
:before_script
)
.
and_return
(
nil
)
end
context
'when job has before script'
do
let
(
:config
)
do
{
before_script:
%w[whoami]
,
script:
'rspec'
}
end
it
'returns correct script'
do
expect
(
entry
.
before_script
).
to
eq
%w[whoami]
end
end
context
'when job does not have before script'
do
let
(
:config
)
do
{
script:
%w[ls test]
}
end
it
'returns correct script'
do
expect
(
entry
.
before_script
).
to
eq
[]
end
end
end
end
...
...
@@ -77,4 +125,61 @@ describe Gitlab::Ci::Config::Node::Job do
expect
(
entry
).
to
be_relevant
end
end
describe
'#commands'
do
context
'when global entry has before script'
do
before
do
allow
(
global
).
to
receive
(
:before_script
)
.
and_return
(
%w[ls pwd]
)
end
context
'when before script is overridden'
do
let
(
:config
)
do
{
before_script:
%w[whoami]
,
script:
'rspec'
}
end
it
'returns correct commands'
do
expect
(
entry
.
commands
).
to
eq
"whoami
\n
rspec"
end
end
context
'when before script is not overriden'
do
let
(
:config
)
do
{
script:
%w[rspec spinach]
}
end
it
'returns correct commands'
do
expect
(
entry
.
commands
).
to
eq
"ls
\n
pwd
\n
rspec
\n
spinach"
end
end
end
context
'when global entry does not have before script'
do
before
do
allow
(
global
).
to
receive
(
:before_script
)
.
and_return
(
nil
)
end
context
'when job has before script'
do
let
(
:config
)
do
{
before_script:
%w[whoami]
,
script:
'rspec'
}
end
it
'returns correct commands'
do
expect
(
entry
.
commands
).
to
eq
"whoami
\n
rspec"
end
end
context
'when job does not have before script'
do
let
(
:config
)
do
{
script:
%w[ls test]
}
end
it
'returns correct commands'
do
expect
(
entry
.
commands
).
to
eq
"ls
\n
test"
end
end
end
end
end
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