Commit 5b7f211c authored by Grzegorz Bizon's avatar Grzegorz Bizon

Add new CI config entry that holds jobs definition

parent 9686a4f2
...@@ -33,11 +33,14 @@ module Gitlab ...@@ -33,11 +33,14 @@ module Gitlab
node :cache, Node::Cache, node :cache, Node::Cache,
description: 'Configure caching between build jobs.' description: 'Configure caching between build jobs.'
node :jobs, Node::Jobs,
description: 'Definition of jobs for this pipeline.'
helpers :before_script, :image, :services, :after_script, helpers :before_script, :image, :services, :after_script,
:variables, :stages, :types, :cache :variables, :stages, :types, :cache, :jobs
def initialize(config) def initialize(config)
return super(config) unless config.is_a?(Hash) return super unless config.is_a?(Hash)
jobs = config.except(*self.class.nodes.keys) jobs = config.except(*self.class.nodes.keys)
global = config.slice(*self.class.nodes.keys) global = config.slice(*self.class.nodes.keys)
...@@ -45,13 +48,6 @@ module Gitlab ...@@ -45,13 +48,6 @@ module Gitlab
super(global.merge(jobs: jobs)) super(global.merge(jobs: jobs))
end end
##
# Temporary refactoring stub
#
def jobs
@config[:jobs]
end
def stages def stages
stages_defined? ? stages_value : types_value stages_defined? ? stages_value : types_value
end end
......
module Gitlab
module Ci
class Config
module Node
##
# Entry that represents a set of jobs.
#
class Jobs < Entry
include Validatable
validations do
validates :config, type: Hash
end
end
end
end
end
end
...@@ -35,7 +35,7 @@ describe Gitlab::Ci::Config::Node::Global do ...@@ -35,7 +35,7 @@ describe Gitlab::Ci::Config::Node::Global do
end end
it 'creates node object for each entry' do it 'creates node object for each entry' do
expect(global.nodes.count).to eq 8 expect(global.nodes.count).to eq 9
end end
it 'creates node object using valid class' do it 'creates node object using valid class' do
...@@ -139,7 +139,7 @@ describe Gitlab::Ci::Config::Node::Global do ...@@ -139,7 +139,7 @@ describe Gitlab::Ci::Config::Node::Global do
describe '#nodes' do describe '#nodes' do
it 'instantizes all nodes' do it 'instantizes all nodes' do
expect(global.nodes.count).to eq 8 expect(global.nodes.count).to eq 9
end end
it 'contains undefined nodes' do it 'contains undefined nodes' do
......
require 'spec_helper'
describe Gitlab::Ci::Config::Node::Jobs do
let(:entry) { described_class.new(config) }
describe 'validations' do
context 'when entry config value is correct' do
let(:config) { { rspec: { script: 'rspec' } } }
describe '#value' do
it 'returns key value' do
expect(entry.value).to eq(rspec: { script: 'rspec' })
end
end
describe '#valid?' do
it 'is valid' do
expect(entry).to be_valid
end
end
end
context 'when entry value is not correct' do
context 'incorrect config value type' do
let(:config) { ['incorrect'] }
describe '#errors' do
it 'saves errors' do
expect(entry.errors)
.to include 'jobs config should be a hash'
end
end
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment