diff options
author | Matija Čupić <matteeyah@gmail.com> | 2018-10-27 03:38:36 +0200 |
---|---|---|
committer | Matija Čupić <matteeyah@gmail.com> | 2018-10-27 03:41:14 +0200 |
commit | 72430483ded51e9a7d01ef70c3dce3dda174fac1 (patch) | |
tree | b50f97467a1b7d503b01229602245df1a2c4300a | |
parent | 44b740f99dfe6a4344c918fd4c94972aa6f9237e (diff) | |
download | gitlab-ce-72430483ded51e9a7d01ef70c3dce3dda174fac1.tar.gz |
Refactor parallelization implementation
* Move the variables to ::Ci::Build#predefined_variables
* Tweak pipeline build seed implementation
-rw-r--r-- | app/models/ci/build.rb | 6 | ||||
-rw-r--r-- | lib/gitlab/ci/pipeline/seed/build.rb | 22 |
2 files changed, 11 insertions, 17 deletions
diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index cdfe8175a42..21e2f289e1e 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -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 diff --git a/lib/gitlab/ci/pipeline/seed/build.rb b/lib/gitlab/ci/pipeline/seed/build.rb index c302acdf073..4b1116ced92 100644 --- a/lib/gitlab/ci/pipeline/seed/build.rb +++ b/lib/gitlab/ci/pipeline/seed/build.rb @@ -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 |