BigW Consortium Gitlab

Commit 1255205d by Grzegorz Bizon

Add method that returns commands for ci job entry

parent bd807503
......@@ -55,12 +55,7 @@ module Ci
{
stage_idx: @stages.index(job[:stage]),
stage: job[:stage],
##
# Refactoring note:
# - before script behaves differently than after script
# - after script returns an array of commands
# - before script should be a concatenated command
commands: [job[:before_script], job[:script]].flatten.compact.join("\n"),
commands: job[:commands],
tag_list: job[:tags] || [],
name: job[:name].to_s,
allow_failure: job[:allow_failure] || false,
......
......@@ -80,7 +80,7 @@ module Gitlab
helpers :before_script, :script, :stage, :type, :after_script,
:cache, :image, :services, :only, :except, :variables,
:artifacts
:artifacts, :commands
def compose!(deps = nil)
super do
......@@ -102,6 +102,10 @@ module Gitlab
@config.merge(to_hash.compact)
end
def commands
(before_script_value.to_a + script_value.to_a).join("\n")
end
private
def inherit!(deps)
......@@ -121,6 +125,7 @@ module Gitlab
{ name: name,
before_script: before_script,
script: script,
commands: commands,
image: image,
services: services,
stage: stage,
......
......@@ -141,9 +141,10 @@ describe Gitlab::Ci::Config::Node::Global do
describe '#jobs' do
it 'returns jobs configuration' do
expect(global.jobs).to eq(
rspec: { script: %w[rspec ls],
name: :rspec,
rspec: { name: :rspec,
script: %w[rspec ls],
before_script: ['ls', 'pwd'],
commands: "ls\npwd\nrspec\nls",
image: 'ruby:2.2',
services: ['postgres:9.1', 'mysql:5.5'],
stage: 'test',
......@@ -151,8 +152,9 @@ describe Gitlab::Ci::Config::Node::Global do
variables: { VAR: 'value' },
after_script: ['make clean'] },
spinach: { name: :spinach,
script: %w[spinach],
before_script: [],
script: %w[spinach],
commands: 'spinach',
image: 'ruby:2.2',
services: ['postgres:9.1', 'mysql:5.5'],
stage: 'test',
......
......@@ -59,27 +59,6 @@ describe Gitlab::Ci::Config::Node::Job do
end
end
describe '#value' do
before { entry.compose! }
context 'when entry is correct' do
let(:config) do
{ before_script: %w[ls pwd],
script: 'rspec',
after_script: %w[cleanup] }
end
it 'returns correct value' do
expect(entry.value)
.to eq(name: :rspec,
before_script: %w[ls pwd],
script: %w[rspec],
stage: 'test',
after_script: %w[cleanup])
end
end
end
describe '#relevant?' do
it 'is a relevant entry' do
expect(entry).to be_relevant
......@@ -122,4 +101,40 @@ describe Gitlab::Ci::Config::Node::Job do
end
end
end
context 'when composed' do
before { entry.compose! }
describe '#value' do
before { entry.compose! }
context 'when entry is correct' do
let(:config) do
{ before_script: %w[ls pwd],
script: 'rspec',
after_script: %w[cleanup] }
end
it 'returns correct value' do
expect(entry.value)
.to eq(name: :rspec,
before_script: %w[ls pwd],
script: %w[rspec],
commands: "ls\npwd\nrspec",
stage: 'test',
after_script: %w[cleanup])
end
end
end
describe '#commands' do
let(:config) do
{ before_script: %w[ls pwd], script: 'rspec' }
end
it 'returns a string of commands concatenated with new line character' do
expect(entry.commands).to eq "ls\npwd\nrspec"
end
end
end
end
......@@ -61,9 +61,11 @@ describe Gitlab::Ci::Config::Node::Jobs do
expect(entry.value).to eq(
rspec: { name: :rspec,
script: %w[rspec],
commands: 'rspec',
stage: 'test' },
spinach: { name: :spinach,
script: %w[spinach],
commands: '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