Move parallelized node index to job options

This commit is contained in:
Matija Čupić 2018-11-01 16:17:08 +01:00
parent 77715e47d6
commit 73e17446ef
No known key found for this signature in database
GPG key ID: 4BAF84FFACD2E5DE
6 changed files with 23 additions and 38 deletions

View file

@ -801,16 +801,12 @@ module Ci
variables.append(key: "CI_COMMIT_TAG", value: ref) if tag?
variables.append(key: "CI_PIPELINE_TRIGGERED", value: 'true') if trigger_request
variables.append(key: "CI_JOB_MANUAL", value: 'true') if action?
variables.append(key: "CI_NODE_INDEX", value: node_index.to_s) if self.options&.include?(:parallel)
variables.append(key: "CI_NODE_INDEX", value: self.options[:instance].to_s) if self.options&.include?(:instance)
variables.append(key: "CI_NODE_TOTAL", value: (self.options&.dig(:parallel) || 1).to_s)
variables.concat(legacy_variables)
end
end
def node_index
name.match(%r{(\d+)/\d+$}).captures[0]
end
def gitlab_version_info
@gitlab_version_info ||= Gitlab::VersionInfo.parse(Gitlab::VERSION)
end

View file

@ -10,8 +10,8 @@ module Gitlab
if config[:parallel]
total = config[:parallel]
names = parallelize_job_names(name, total)
parallelized_jobs[name] = names
Hash[names.collect { |job_name| [job_name.to_sym, config.merge(name: job_name)] }]
parallelized_jobs[name] = names.map(&:first)
Hash[names.collect { |job_name, index| [job_name.to_sym, config.merge(name: job_name, instance: index)] }]
else
{ name => config }
end
@ -39,7 +39,7 @@ module Gitlab
jobs = []
total.times do |idx|
jobs << "#{name} #{idx + 1}/#{total}"
jobs << ["#{name} #{idx + 1}/#{total}", idx + 1]
end
jobs

View file

@ -51,6 +51,7 @@ module Gitlab
environment: job[:environment],
retry: job[:retry],
parallel: job[:parallel],
instance: job[:instance],
start_in: job[:start_in]
}.compact }
end

View file

@ -2,7 +2,7 @@ require 'fast_spec_helper'
describe Gitlab::Ci::Config::Normalizer do
let(:job_name) { :rspec }
let(:job_config) { { script: 'rspec', parallel: 5 } }
let(:job_config) { { script: 'rspec', parallel: 5, name: 'rspec' } }
let(:config) { { job_name => job_config } }
describe '.normalize_jobs' do
@ -13,14 +13,18 @@ describe Gitlab::Ci::Config::Normalizer do
end
it 'has parallelized jobs' do
job_names = described_class.send(:parallelize_job_names, job_name, 5).map(&:to_sym)
job_names = described_class.send(:parallelize_job_names, job_name, 5).map { |job_name, index| job_name.to_sym }
is_expected.to include(*job_names)
end
it 'sets job instance in options' do
expect(subject.values).to all(include(:instance))
end
it 'parallelizes jobs with original config' do
original_config = config[job_name].except(:name)
configs = subject.values.map { |config| config.except(:name) }
configs = subject.values.map { |config| config.except(:name, :instance) }
expect(configs).to all(eq(original_config))
end
@ -30,7 +34,7 @@ describe Gitlab::Ci::Config::Normalizer do
subject { described_class.send(:parallelize_job_names, job_name, 5) }
it 'returns parallelized names' do
is_expected.to all(match(%r{#{job_name} \d+/\d+}))
expect(subject.map(&:first)).to all(match(%r{#{job_name} \d+/\d+}))
end
end
end

View file

@ -657,9 +657,17 @@ module Gitlab
it 'returns parallelized jobs' do
config_processor = Gitlab::Ci::YamlProcessor.new(config)
builds = config_processor.stage_builds_attributes('test')
build_options = builds.map { |build| build[:options] }
expect(builds.size).to eq(5)
expect(builds.map { |build| build[:options] }).to all(include(parallel: parallel))
expect(build_options).to all(include(:instance, parallel: parallel))
end
it 'does not have the original job' do
config_processor = Gitlab::Ci::YamlProcessor.new(config)
builds = config_processor.stage_builds_attributes('test')
expect(builds).not_to include(:rspec)
end
end
end

View file

@ -2348,6 +2348,7 @@ describe Ci::Build do
before do
build.options[:parallel] = total
build.options[:instance] = index
build.name = "#{build.name} #{index}/#{total}"
end
@ -2470,31 +2471,6 @@ describe Ci::Build do
end
end
end
describe '#node_index' do
subject { build.send(:node_index) }
let(:index) { 4 }
context 'when build has only one index' do
before do
build.name = "#{build.name} #{index}/5"
end
it 'returns the index' do
expect(subject).to eq(index.to_s)
end
end
context 'when build has more than one one index' do
before do
build.name = "test_build 1/3 #{index}/5"
end
it 'returns the last index' do
expect(subject).to eq(index.to_s)
end
end
end
end
describe '#scoped_variables' do