diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2018-03-21 12:59:11 +0300 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2018-03-21 12:59:11 +0300 |
commit | e79ebabb72f66b24f0523584b5ad2a61c88c330d (patch) | |
tree | 4de1375058c6d9264d96ec7812501e70b30fc750 /lib/gitlab/ci/pipeline/chain | |
parent | 6f20134d7177bfd50cf064153832115c095a13ef (diff) |
Populate pipeline with objects before creating it
Diffstat (limited to 'lib/gitlab/ci/pipeline/chain')
-rw-r--r-- | lib/gitlab/ci/pipeline/chain/create.rb | 7 | ||||
-rw-r--r-- | lib/gitlab/ci/pipeline/chain/populate.rb | 32 |
2 files changed, 32 insertions, 7 deletions
diff --git a/lib/gitlab/ci/pipeline/chain/create.rb b/lib/gitlab/ci/pipeline/chain/create.rb index 753d0e89b1e..930d767b0f3 100644 --- a/lib/gitlab/ci/pipeline/chain/create.rb +++ b/lib/gitlab/ci/pipeline/chain/create.rb @@ -9,13 +9,6 @@ module Gitlab ::Ci::Pipeline.transaction do pipeline.save! - @command.seeds_block&.call(pipeline) - - pipeline.stage_seeds.each do |seed| - seed.user = current_user - seed.to_resource.save! - end - # TODO populate environments with find_or_initialize_by in the chain too. ## diff --git a/lib/gitlab/ci/pipeline/chain/populate.rb b/lib/gitlab/ci/pipeline/chain/populate.rb new file mode 100644 index 00000000000..5368ff15481 --- /dev/null +++ b/lib/gitlab/ci/pipeline/chain/populate.rb @@ -0,0 +1,32 @@ +module Gitlab + module Ci + module Pipeline + module Chain + class Populate < Chain::Base + PopulateError = Class.new(StandardError) + + def perform! + ## + # Populate pipeline with seeds block. + # + # It comes from a block argument to CreatePipelineService#execute. + # + @command.seeds_block&.call(pipeline) + + pipeline.stage_seeds.each do |seed| + seed.user = current_user + + pipeline.stages << seed.to_resource + end + + raise Populate::PopulateError if pipeline.persisted? + end + + def break? + pipeline.persisted? + end + end + end + end + end +end |