Commit 72430483 authored by Matija Čupić's avatar Matija Čupić

Refactor parallelization implementation

* Move the variables to ::Ci::Build#predefined_variables
* Tweak pipeline build seed implementation
parent 44b740f9
......@@ -801,10 +801,16 @@ 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[:parallel]
variables.append(key: "CI_NODE_TOTAL", value: self.options.fetch(: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
......
......@@ -24,22 +24,14 @@ module Gitlab
end
end
def parallelized?
@attributes[:options].include?(:parallel)
def parallel?
!!@attributes.dig(:options, :parallel)
end
def parallelize_build
builds = []
total = @attributes[:options][:parallel]
total.times do |i|
build = ::Ci::Build.new(attributes.merge(options: { variables: { CI_NODE_INDEX: i + 1, CI_NODE_TOTAL: total } }))
build.name = build.name + "_#{i + 1}/#{total}"
builds << build
end
builds
Array.new(total) { ::Ci::Build.new(attributes) }
.each_with_index { |build, idx| build.name = "#{build.name} #{idx + 1}/#{total}" }
end
def attributes
......@@ -56,11 +48,7 @@ module Gitlab
def to_resource
strong_memoize(:resource) do
if parallelized?
parallelize_build
else
::Ci::Build.new(attributes)
end
parallel? ? parallelize_build : ::Ci::Build.new(attributes)
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