BigW Consortium Gitlab

Commit 489e9be4 by Grzegorz Bizon

Add CI job script node in new config processor

parent 3c5b1da2
......@@ -15,13 +15,16 @@ module Gitlab
node :before_script, Script,
description: 'Global before script overridden in this job.'
node :script, JobScript,
description: 'Commands that will be executed in this job.'
node :stage, Stage,
description: 'Pipeline stage this job will be executed into.'
node :type, Stage,
description: 'Deprecated: stage this job will be executed into.'
helpers :before_script, :stage, :type
helpers :before_script, :script, :stage, :type
def value
raise InvalidError unless valid?
......@@ -36,8 +39,9 @@ module Gitlab
private
def to_hash
{ before_script: before_script,
stage: stage }
{ before_script: before_script_value,
script: script_value,
stage: stage_value }
end
def compose!
......
module Gitlab
module Ci
class Config
module Node
##
# Entry that represents a job script.
#
class JobScript < Entry
include Validatable
validations do
include LegacyValidationHelpers
validate :string_or_array_of_strings
def string_or_array_of_strings
unless validate_string(config) || validate_array_of_strings(config)
errors.add(:config,
'should be a string or an array of strings')
end
end
end
def value
[@config].flatten
end
end
end
end
end
end
......@@ -129,8 +129,8 @@ describe Gitlab::Ci::Config::Node::Global do
describe '#jobs' do
it 'returns jobs configuration' do
expect(global.jobs)
.to eq(rspec: { script: 'rspec', stage: 'test' },
spinach: { script: 'spinach', stage: 'test' })
.to eq(rspec: { script: %w[rspec], stage: 'test' },
spinach: { script: %w[spinach], stage: 'test' })
end
end
end
......
require 'spec_helper'
describe Gitlab::Ci::Config::Node::JobScript do
let(:entry) { described_class.new(config) }
context 'when entry config value is an array' do
let(:config) { ['ls', 'pwd'] }
describe '#value' do
it 'returns array of strings' do
expect(entry.value).to eq config
end
end
describe '#errors' do
it 'does not append errors' do
expect(entry.errors).to be_empty
end
end
end
context 'when entry config value is a string' do
let(:config) { 'ls' }
describe '#value' do
it 'returns array with single element' do
expect(entry.value).to eq ['ls']
end
end
describe '#valid?' do
it 'is valid' do
expect(entry).to be_valid
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 'job script config should be a ' \
'string or an array of strings'
end
end
end
end
......@@ -54,7 +54,7 @@ describe Gitlab::Ci::Config::Node::Job do
it 'returns correct value' do
expect(entry.value)
.to eq(before_script: %w[ls pwd],
script: 'rspec',
script: %w[rspec],
stage: 'test')
end
end
......
......@@ -62,8 +62,8 @@ describe Gitlab::Ci::Config::Node::Jobs do
describe '#value' do
it 'returns key value' do
expect(entry.value)
.to eq(rspec: { script: 'rspec', stage: 'test' },
spinach: { script: 'spinach', stage: 'test' })
.to eq(rspec: { script: %w[rspec], stage: 'test' },
spinach: { script: %w[spinach], stage: 'test' })
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