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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
62f704c5
Commit
62f704c5
authored
Aug 29, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make it possible to inherit global ci config nodes
parent
30f58cf3
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
80 additions
and
8 deletions
+80
-8
lib/gitlab/ci/config/node/job.rb
lib/gitlab/ci/config/node/job.rb
+15
-0
spec/lib/gitlab/ci/config/node/global_spec.rb
spec/lib/gitlab/ci/config/node/global_spec.rb
+24
-6
spec/lib/gitlab/ci/config/node/job_spec.rb
spec/lib/gitlab/ci/config/node/job_spec.rb
+41
-2
No files found.
lib/gitlab/ci/config/node/job.rb
View file @
62f704c5
...
@@ -90,6 +90,8 @@ module Gitlab
...
@@ -90,6 +90,8 @@ module Gitlab
@entries
.
delete
(
:type
)
@entries
.
delete
(
:type
)
end
end
inherit!
(
deps
)
end
end
def
name
def
name
...
@@ -102,6 +104,19 @@ module Gitlab
...
@@ -102,6 +104,19 @@ module Gitlab
private
private
def
inherit!
(
deps
)
return
unless
deps
self
.
class
.
nodes
.
each_key
do
|
key
|
global_entry
=
deps
[
key
]
job_entry
=
@entries
[
key
]
if
global_entry
.
specified?
&&
!
job_entry
.
specified?
@entries
[
key
]
=
global_entry
end
end
end
def
to_hash
def
to_hash
{
name:
name
,
{
name:
name
,
before_script:
before_script
,
before_script:
before_script
,
...
...
spec/lib/gitlab/ci/config/node/global_spec.rb
View file @
62f704c5
...
@@ -14,7 +14,7 @@ describe Gitlab::Ci::Config::Node::Global do
...
@@ -14,7 +14,7 @@ describe Gitlab::Ci::Config::Node::Global do
end
end
context
'when hash is valid'
do
context
'when hash is valid'
do
context
'when
all
entries defined'
do
context
'when
some
entries defined'
do
let
(
:hash
)
do
let
(
:hash
)
do
{
before_script:
[
'ls'
,
'pwd'
],
{
before_script:
[
'ls'
,
'pwd'
],
image:
'ruby:2.2'
,
image:
'ruby:2.2'
,
...
@@ -24,7 +24,7 @@ describe Gitlab::Ci::Config::Node::Global do
...
@@ -24,7 +24,7 @@ describe Gitlab::Ci::Config::Node::Global do
stages:
[
'build'
,
'pages'
],
stages:
[
'build'
,
'pages'
],
cache:
{
key:
'k'
,
untracked:
true
,
paths:
[
'public/'
]
},
cache:
{
key:
'k'
,
untracked:
true
,
paths:
[
'public/'
]
},
rspec:
{
script:
%w[rspec ls]
},
rspec:
{
script:
%w[rspec ls]
},
spinach:
{
script:
'spinach'
}
}
spinach:
{
before_script:
[],
variables:
{},
script:
'spinach'
}
}
end
end
describe
'#compose!'
do
describe
'#compose!'
do
...
@@ -76,6 +76,12 @@ describe Gitlab::Ci::Config::Node::Global do
...
@@ -76,6 +76,12 @@ describe Gitlab::Ci::Config::Node::Global do
context
'when composed'
do
context
'when composed'
do
before
{
global
.
compose!
}
before
{
global
.
compose!
}
describe
'#errors'
do
it
'has no errors'
do
expect
(
global
.
errors
).
to
be_empty
end
end
describe
'#before_script'
do
describe
'#before_script'
do
it
'returns correct script'
do
it
'returns correct script'
do
expect
(
global
.
before_script
).
to
eq
[
'ls'
,
'pwd'
]
expect
(
global
.
before_script
).
to
eq
[
'ls'
,
'pwd'
]
...
@@ -135,12 +141,24 @@ describe Gitlab::Ci::Config::Node::Global do
...
@@ -135,12 +141,24 @@ describe Gitlab::Ci::Config::Node::Global do
describe
'#jobs'
do
describe
'#jobs'
do
it
'returns jobs configuration'
do
it
'returns jobs configuration'
do
expect
(
global
.
jobs
).
to
eq
(
expect
(
global
.
jobs
).
to
eq
(
rspec:
{
name: :rspec
,
rspec:
{
script:
%w[rspec ls]
,
script:
%w[rspec ls]
,
name: :rspec
,
stage:
'test'
},
before_script:
[
'ls'
,
'pwd'
],
image:
'ruby:2.2'
,
services:
[
'postgres:9.1'
,
'mysql:5.5'
],
stage:
'test'
,
cache:
{
key:
'k'
,
untracked:
true
,
paths:
[
'public/'
]
},
variables:
{
VAR
:
'value'
},
after_script:
[
'make clean'
]
},
spinach:
{
name: :spinach
,
spinach:
{
name: :spinach
,
script:
%w[spinach]
,
script:
%w[spinach]
,
stage:
'test'
}
before_script:
[],
image:
'ruby:2.2'
,
services:
[
'postgres:9.1'
,
'mysql:5.5'
],
stage:
'test'
,
cache:
{
key:
'k'
,
untracked:
true
,
paths:
[
'public/'
]
},
variables:
{},
after_script:
[
'make clean'
]
},
)
)
end
end
end
end
...
...
spec/lib/gitlab/ci/config/node/job_spec.rb
View file @
62f704c5
...
@@ -3,9 +3,9 @@ require 'spec_helper'
...
@@ -3,9 +3,9 @@ require 'spec_helper'
describe
Gitlab
::
Ci
::
Config
::
Node
::
Job
do
describe
Gitlab
::
Ci
::
Config
::
Node
::
Job
do
let
(
:entry
)
{
described_class
.
new
(
config
,
name: :rspec
)
}
let
(
:entry
)
{
described_class
.
new
(
config
,
name: :rspec
)
}
describe
'validations'
do
before
{
entry
.
compose!
}
before
{
entry
.
compose!
}
describe
'validations'
do
context
'when entry config value is correct'
do
context
'when entry config value is correct'
do
let
(
:config
)
{
{
script:
'rspec'
}
}
let
(
:config
)
{
{
script:
'rspec'
}
}
...
@@ -60,6 +60,8 @@ describe Gitlab::Ci::Config::Node::Job do
...
@@ -60,6 +60,8 @@ describe Gitlab::Ci::Config::Node::Job do
end
end
describe
'#value'
do
describe
'#value'
do
before
{
entry
.
compose!
}
context
'when entry is correct'
do
context
'when entry is correct'
do
let
(
:config
)
do
let
(
:config
)
do
{
before_script:
%w[ls pwd]
,
{
before_script:
%w[ls pwd]
,
...
@@ -83,4 +85,41 @@ describe Gitlab::Ci::Config::Node::Job do
...
@@ -83,4 +85,41 @@ describe Gitlab::Ci::Config::Node::Job do
expect
(
entry
).
to
be_relevant
expect
(
entry
).
to
be_relevant
end
end
end
end
describe
'#compose!'
do
let
(
:unspecified
)
{
double
(
'unspecified'
,
'specified?'
=>
false
)
}
let
(
:specified
)
do
double
(
'specified'
,
'specified?'
=>
true
,
value:
'specified'
)
end
let
(
:deps
)
{
spy
(
'deps'
,
'[]'
=>
unspecified
)
}
context
'when job config overrides global config'
do
before
{
entry
.
compose!
(
deps
)
}
let
(
:config
)
do
{
image:
'some_image'
,
cache:
{
key:
'test'
}
}
end
it
'overrides global config'
do
expect
(
entry
[
:image
].
value
).
to
eq
'some_image'
expect
(
entry
[
:cache
].
value
).
to
eq
(
key:
'test'
)
end
end
context
'when job config does not override global config'
do
before
do
allow
(
deps
).
to
receive
(
'[]'
).
with
(
:image
).
and_return
(
specified
)
entry
.
compose!
(
deps
)
end
let
(
:config
)
{
{
script:
'ls'
,
cache:
{
key:
'test'
}
}
}
it
'uses config from global entry'
do
expect
(
entry
[
:image
].
value
).
to
eq
'specified'
expect
(
entry
[
:cache
].
value
).
to
eq
(
key:
'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