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 ...@@ -801,10 +801,16 @@ module Ci
variables.append(key: "CI_COMMIT_TAG", value: ref) if tag? 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_PIPELINE_TRIGGERED", value: 'true') if trigger_request
variables.append(key: "CI_JOB_MANUAL", value: 'true') if action? 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) variables.concat(legacy_variables)
end end
end end
def node_index
name.match(%r{(\d+)/\d+$}).captures[0]
end
def gitlab_version_info def gitlab_version_info
@gitlab_version_info ||= Gitlab::VersionInfo.parse(Gitlab::VERSION) @gitlab_version_info ||= Gitlab::VersionInfo.parse(Gitlab::VERSION)
end end
......
...@@ -24,22 +24,14 @@ module Gitlab ...@@ -24,22 +24,14 @@ module Gitlab
end end
end end
def parallelized? def parallel?
@attributes[:options].include?(:parallel) !!@attributes.dig(:options, :parallel)
end end
def parallelize_build def parallelize_build
builds = []
total = @attributes[:options][:parallel] total = @attributes[:options][:parallel]
Array.new(total) { ::Ci::Build.new(attributes) }
total.times do |i| .each_with_index { |build, idx| build.name = "#{build.name} #{idx + 1}/#{total}" }
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
end end
def attributes def attributes
...@@ -56,11 +48,7 @@ module Gitlab ...@@ -56,11 +48,7 @@ module Gitlab
def to_resource def to_resource
strong_memoize(:resource) do strong_memoize(:resource) do
if parallelized? parallel? ? parallelize_build : ::Ci::Build.new(attributes)
parallelize_build
else
::Ci::Build.new(attributes)
end
end end
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