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
Boxiang Sun
gitlab-ce
Commits
9a4117ab
Commit
9a4117ab
authored
Aug 17, 2018
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for `extends` key in CI/CD configuration
parent
88086559
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
54 additions
and
9 deletions
+54
-9
lib/gitlab/ci/config.rb
lib/gitlab/ci/config.rb
+12
-2
lib/gitlab/ci/config/entry/job.rb
lib/gitlab/ci/config/entry/job.rb
+7
-4
lib/gitlab/ci/yaml_processor.rb
lib/gitlab/ci/yaml_processor.rb
+1
-1
spec/lib/gitlab/ci/config_spec.rb
spec/lib/gitlab/ci/config_spec.rb
+34
-2
No files found.
lib/gitlab/ci/config.rb
View file @
9a4117ab
...
@@ -4,12 +4,17 @@ module Gitlab
...
@@ -4,12 +4,17 @@ module Gitlab
# Base GitLab CI Configuration facade
# Base GitLab CI Configuration facade
#
#
class
Config
class
Config
# EE would override this and utilize opts argument
ConfigError
=
Class
.
new
(
StandardError
)
def
initialize
(
config
,
opts
=
{})
def
initialize
(
config
,
opts
=
{})
@config
=
Loader
.
new
(
config
).
load!
@config
=
Extendable
::
Collection
.
new
(
build_config
(
config
,
opts
))
.
to_hash
@global
=
Entry
::
Global
.
new
(
@config
)
@global
=
Entry
::
Global
.
new
(
@config
)
@global
.
compose!
@global
.
compose!
rescue
Loader
::
FormatError
,
Extendable
::
Collection
::
ExtensionError
=>
e
raise
Config
::
ConfigError
,
e
.
message
end
end
def
valid?
def
valid?
...
@@ -58,6 +63,11 @@ module Gitlab
...
@@ -58,6 +63,11 @@ module Gitlab
def
jobs
def
jobs
@global
.
jobs_value
@global
.
jobs_value
end
end
# 'opts' argument is used in EE see /ee/lib/ee/gitlab/ci/config.rb
def
build_config
(
config
,
opts
=
{})
Loader
.
new
(
config
).
load!
end
end
end
end
end
end
end
lib/gitlab/ci/config/entry/job.rb
View file @
9a4117ab
...
@@ -9,9 +9,10 @@ module Gitlab
...
@@ -9,9 +9,10 @@ module Gitlab
include
Configurable
include
Configurable
include
Attributable
include
Attributable
ALLOWED_KEYS
=
%i[tags script only except type image services allow_failure
ALLOWED_KEYS
=
%i[tags script only except type image services
type stage when artifacts cache dependencies before_script
allow_failure type stage when artifacts cache
after_script variables environment coverage retry]
.
freeze
dependencies before_script after_script variables
environment coverage retry extends]
.
freeze
validations
do
validations
do
validates
:config
,
allowed_keys:
ALLOWED_KEYS
validates
:config
,
allowed_keys:
ALLOWED_KEYS
...
@@ -32,6 +33,7 @@ module Gitlab
...
@@ -32,6 +33,7 @@ module Gitlab
'always or manual'
}
'always or manual'
}
validates
:dependencies
,
array_of_strings:
true
validates
:dependencies
,
array_of_strings:
true
validates
:extends
,
type:
String
end
end
end
end
...
@@ -81,7 +83,8 @@ module Gitlab
...
@@ -81,7 +83,8 @@ module Gitlab
:cache
,
:image
,
:services
,
:only
,
:except
,
:variables
,
:cache
,
:image
,
:services
,
:only
,
:except
,
:variables
,
:artifacts
,
:commands
,
:environment
,
:coverage
,
:retry
:artifacts
,
:commands
,
:environment
,
:coverage
,
:retry
attributes
:script
,
:tags
,
:allow_failure
,
:when
,
:dependencies
,
:retry
attributes
:script
,
:tags
,
:allow_failure
,
:when
,
:dependencies
,
:retry
,
:extends
def
compose!
(
deps
=
nil
)
def
compose!
(
deps
=
nil
)
super
do
super
do
...
...
lib/gitlab/ci/yaml_processor.rb
View file @
9a4117ab
...
@@ -16,7 +16,7 @@ module Gitlab
...
@@ -16,7 +16,7 @@ module Gitlab
end
end
initial_parsing
initial_parsing
rescue
Gitlab
::
Ci
::
Config
::
Loader
::
Format
Error
=>
e
rescue
Gitlab
::
Ci
::
Config
::
Config
Error
=>
e
raise
ValidationError
,
e
.
message
raise
ValidationError
,
e
.
message
end
end
...
...
spec/lib/gitlab/ci/config_spec.rb
View file @
9a4117ab
require
'spec_helper'
require
'fast_spec_helper'
require_dependency
'active_model'
describe
Gitlab
::
Ci
::
Config
do
describe
Gitlab
::
Ci
::
Config
do
let
(
:config
)
do
let
(
:config
)
do
...
@@ -42,6 +44,36 @@ describe Gitlab::Ci::Config do
...
@@ -42,6 +44,36 @@ describe Gitlab::Ci::Config do
end
end
end
end
context
'when using extendable hash'
do
let
(
:yml
)
do
<<-
EOS
image: ruby:2.2
rspec:
script: rspec
test:
extends: rspec
image: ruby:alpine
EOS
end
it
'correctly extends the hash'
do
hash
=
{
image:
'ruby:2.2'
,
rspec:
{
script:
'rspec'
},
test:
{
extends:
'rspec'
,
image:
'ruby:alpine'
,
script:
'rspec'
}
}
expect
(
config
).
to
be_valid
expect
(
config
.
to_hash
).
to
eq
hash
end
end
context
'when config is invalid'
do
context
'when config is invalid'
do
context
'when yml is incorrect'
do
context
'when yml is incorrect'
do
let
(
:yml
)
{
'// invalid'
}
let
(
:yml
)
{
'// invalid'
}
...
@@ -49,7 +81,7 @@ describe Gitlab::Ci::Config do
...
@@ -49,7 +81,7 @@ describe Gitlab::Ci::Config do
describe
'.new'
do
describe
'.new'
do
it
'raises error'
do
it
'raises error'
do
expect
{
config
}.
to
raise_error
(
expect
{
config
}.
to
raise_error
(
::
Gitlab
::
Ci
::
Config
::
Loader
::
Format
Error
,
described_class
::
Config
Error
,
/Invalid configuration format/
/Invalid configuration format/
)
)
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