Commit 1bf9e347 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Move except and only job nodes to new CI config

parent 27e88efc
...@@ -38,8 +38,14 @@ module Gitlab ...@@ -38,8 +38,14 @@ module Gitlab
node :services, Services, node :services, Services,
description: 'Services that will be used to execute this job.' description: 'Services that will be used to execute this job.'
node :only, While,
description: 'Refs policy this job will be executed for.'
node :except, While,
description: 'Refs policy this job will be executed for.'
helpers :before_script, :script, :stage, :type, :after_script, helpers :before_script, :script, :stage, :type, :after_script,
:cache, :image, :services :cache, :image, :services, :only, :except
def name def name
@metadata[:name] @metadata[:name]
...@@ -59,6 +65,8 @@ module Gitlab ...@@ -59,6 +65,8 @@ module Gitlab
services: services, services: services,
stage: stage, stage: stage,
cache: cache, cache: cache,
only: only,
except: except,
after_script: after_script } after_script: after_script }
end end
......
module Gitlab
module Ci
class Config
module Node
##
# Entry that represents a ref and trigger policy for the job.
#
class While < Entry
include Validatable
validations do
include LegacyValidationHelpers
validate :array_of_strings_or_regexps
def array_of_strings_or_regexps
unless validate_array_of_strings_or_regexps(config)
errors.add(:config, 'should be an array of strings or regexps')
end
end
end
end
end
end
end
end
...@@ -163,7 +163,7 @@ module Ci ...@@ -163,7 +163,7 @@ module Ci
shared_examples 'raises an error' do shared_examples 'raises an error' do
it do it do
expect { processor }.to raise_error(GitlabCiYamlProcessor::ValidationError, 'rspec job: only parameter should be an array of strings or regexps') expect { processor }.to raise_error(GitlabCiYamlProcessor::ValidationError, 'jobs:rspec:only config should be an array of strings or regexps')
end end
end end
...@@ -319,7 +319,7 @@ module Ci ...@@ -319,7 +319,7 @@ module Ci
shared_examples 'raises an error' do shared_examples 'raises an error' do
it do it do
expect { processor }.to raise_error(GitlabCiYamlProcessor::ValidationError, 'rspec job: except parameter should be an array of strings or regexps') expect { processor }.to raise_error(GitlabCiYamlProcessor::ValidationError, 'jobs:rspec:except config should be an array of strings or regexps')
end end
end end
......
require 'spec_helper'
describe Gitlab::Ci::Config::Node::While do
let(:entry) { described_class.new(config) }
describe 'validations' do
context 'when entry config value is valid' do
context 'when config is a branch or tag name' do
let(:config) { %w[master feature/branch] }
describe '#valid?' do
it 'is valid' do
expect(entry).to be_valid
end
end
describe '#value' do
it 'returns key value' do
expect(entry.value).to eq config
end
end
end
context 'when config is a regexp' do
let(:config) { ['/^issue-.*$/'] }
describe '#valid?' do
it 'is valid' do
expect(entry).to be_valid
end
end
end
context 'when config is a special keyword' do
let(:config) { %w[tags triggers branches] }
describe '#valid?' do
it 'is valid' do
expect(entry).to be_valid
end
end
end
end
context 'when entry value is not valid' do
let(:config) { [1] }
describe '#errors' do
it 'saves errors' do
expect(entry.errors)
.to include 'while config should be an array of strings or regexps'
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