summaryrefslogtreecommitdiff
path: root/lib/gitlab/ci/pipeline/chain/populate.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/ci/pipeline/chain/populate.rb')
-rw-r--r--lib/gitlab/ci/pipeline/chain/populate.rb44
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/gitlab/ci/pipeline/chain/populate.rb b/lib/gitlab/ci/pipeline/chain/populate.rb
new file mode 100644
index 00000000000..f34c11ca3c2
--- /dev/null
+++ b/lib/gitlab/ci/pipeline/chain/populate.rb
@@ -0,0 +1,44 @@
+module Gitlab
+ module Ci
+ module Pipeline
+ module Chain
+ class Populate < Chain::Base
+ include Chain::Helpers
+
+ PopulateError = Class.new(StandardError)
+
+ def perform!
+ # Allocate next IID. This operation must be outside of transactions of pipeline creations.
+ pipeline.ensure_project_iid!
+
+ ##
+ # Populate pipeline with block argument of CreatePipelineService#execute.
+ #
+ @command.seeds_block&.call(pipeline)
+
+ ##
+ # Populate pipeline with all stages, and stages with builds.
+ #
+ pipeline.stage_seeds.each do |stage|
+ pipeline.stages << stage.to_resource
+ end
+
+ if pipeline.stages.none?
+ return error('No stages / jobs for this pipeline.')
+ end
+
+ if pipeline.invalid?
+ return error('Failed to build the pipeline!')
+ end
+
+ raise Populate::PopulateError if pipeline.persisted?
+ end
+
+ def break?
+ pipeline.errors.any?
+ end
+ end
+ end
+ end
+ end
+end