Commit f7c80e9f authored by Grzegorz Bizon's avatar Grzegorz Bizon

Revert references to global node in CI job entry

parent 56ae9f6b
...@@ -80,7 +80,7 @@ module Ci ...@@ -80,7 +80,7 @@ module Ci
{ {
stage_idx: @stages.index(job[:stage]), stage_idx: @stages.index(job[:stage]),
stage: job[:stage], stage: job[:stage],
commands: job[:commands], commands: [job[:before_script] || @before_script, job[:script]].flatten.compact.join("\n"),
tag_list: job[:tags] || [], tag_list: job[:tags] || [],
name: name, name: name,
only: job[:only], only: job[:only],
...@@ -112,12 +112,8 @@ module Ci ...@@ -112,12 +112,8 @@ module Ci
end end
def validate_job_keys!(name, job) def validate_job_keys!(name, job)
##
# TODO, remove refactoring keys
#
refactoring_keys = [:commands]
job.keys.each do |key| job.keys.each do |key|
unless (ALLOWED_JOB_KEYS + refactoring_keys).include? key unless ALLOWED_JOB_KEYS.include? key
raise ValidationError, "#{name} job: unknown parameter #{key}" raise ValidationError, "#{name} job: unknown parameter #{key}"
end end
end end
......
...@@ -43,25 +43,13 @@ module Gitlab ...@@ -43,25 +43,13 @@ module Gitlab
@config.merge(to_hash.compact) @config.merge(to_hash.compact)
end end
def before_script
if before_script_defined?
before_script_value
else
@global.before_script
end
end
def commands
[before_script, script].compact.join("\n")
end
private private
def to_hash def to_hash
{ script: script, { before_script: before_script_value,
stage: stage, script: script_value,
commands: commands, stage: stage_value,
after_script: after_script } after_script: after_script_value }
end end
def compose! def compose!
......
...@@ -130,11 +130,9 @@ describe Gitlab::Ci::Config::Node::Global do ...@@ -130,11 +130,9 @@ describe Gitlab::Ci::Config::Node::Global do
it 'returns jobs configuration' do it 'returns jobs configuration' do
expect(global.jobs) expect(global.jobs)
.to eq(rspec: { script: %w[rspec ls], .to eq(rspec: { script: %w[rspec ls],
stage: 'test', stage: 'test' },
commands: "ls\npwd\nrspec\nls" },
spinach: { script: %w[spinach], spinach: { script: %w[spinach],
stage: 'test', stage: 'test' })
commands: "ls\npwd\nspinach" })
end end
end end
end end
......
...@@ -66,131 +66,15 @@ describe Gitlab::Ci::Config::Node::Job do ...@@ -66,131 +66,15 @@ describe Gitlab::Ci::Config::Node::Job do
expect(entry.value) expect(entry.value)
.to eq(before_script: %w[ls pwd], .to eq(before_script: %w[ls pwd],
script: %w[rspec], script: %w[rspec],
commands: "ls\npwd\nrspec",
stage: 'test', stage: 'test',
after_script: %w[cleanup]) after_script: %w[cleanup])
end end
end end
end end
describe '#before_script' do
context 'when global entry has before script' do
before do
allow(global).to receive(:before_script)
.and_return(%w[ls pwd])
end
context 'when before script is overridden' do
let(:config) do
{ before_script: %w[whoami],
script: 'rspec' }
end
it 'returns correct script' do
expect(entry.before_script).to eq %w[whoami]
end
end
context 'when before script is not overriden' do
let(:config) do
{ script: %w[spinach] }
end
it 'returns correct script' do
expect(entry.before_script).to eq %w[ls pwd]
end
end
end
context 'when global entry does not have before script' do
before do
allow(global).to receive(:before_script)
.and_return(nil)
end
context 'when job has before script' do
let(:config) do
{ before_script: %w[whoami],
script: 'rspec' }
end
it 'returns correct script' do
expect(entry.before_script).to eq %w[whoami]
end
end
context 'when job does not have before script' do
let(:config) do
{ script: %w[ls test] }
end
it 'returns correct script' do
expect(entry.before_script).to be_nil
end
end
end
end
describe '#relevant?' do describe '#relevant?' do
it 'is a relevant entry' do it 'is a relevant entry' do
expect(entry).to be_relevant expect(entry).to be_relevant
end end
end end
describe '#commands' do
context 'when global entry has before script' do
before do
allow(global).to receive(:before_script)
.and_return(%w[ls pwd])
end
context 'when before script is overridden' do
let(:config) do
{ before_script: %w[whoami],
script: 'rspec' }
end
it 'returns correct commands' do
expect(entry.commands).to eq "whoami\nrspec"
end
end
context 'when before script is not overriden' do
let(:config) do
{ script: %w[rspec spinach] }
end
it 'returns correct commands' do
expect(entry.commands).to eq "ls\npwd\nrspec\nspinach"
end
end
end
context 'when global entry does not have before script' do
before do
allow(global).to receive(:before_script)
.and_return(nil)
end
context 'when job has before script' do
let(:config) do
{ before_script: %w[whoami],
script: 'rspec' }
end
it 'returns correct commands' do
expect(entry.commands).to eq "whoami\nrspec"
end
end
context 'when job does not have before script' do
let(:config) do
{ script: %w[ls test] }
end
it 'returns correct commands' do
expect(entry.commands).to eq "ls\ntest"
end
end
end
end
end end
...@@ -64,10 +64,8 @@ describe Gitlab::Ci::Config::Node::Jobs do ...@@ -64,10 +64,8 @@ describe Gitlab::Ci::Config::Node::Jobs do
it 'returns key value' do it 'returns key value' do
expect(entry.value) expect(entry.value)
.to eq(rspec: { script: %w[rspec], .to eq(rspec: { script: %w[rspec],
commands: 'rspec',
stage: 'test' }, stage: 'test' },
spinach: { script: %w[spinach], spinach: { script: %w[spinach],
commands: 'spinach',
stage: 'test' }) stage: 'test' })
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