debian-mirror-gitlab/lib/gitlab/ci/pipeline/chain/populate.rb

56 lines
1.6 KiB
Ruby
Raw Normal View History

2018-12-13 13:39:08 +05:30
# frozen_string_literal: true
2018-05-09 12:01:36 +05:30
module Gitlab
module Ci
module Pipeline
module Chain
class Populate < Chain::Base
include Chain::Helpers
PopulateError = Class.new(StandardError)
def perform!
2018-11-08 19:23:39 +05:30
# Allocate next IID. This operation must be outside of transactions of pipeline creations.
pipeline.ensure_project_iid!
2019-03-02 22:35:43 +05:30
# Protect the pipeline. This is assigned in Populate instead of
# Build to prevent erroring out on ambiguous refs.
pipeline.protected = @command.protected_ref?
2018-05-09 12:01:36 +05:30
##
# Populate pipeline with block argument of CreatePipelineService#execute.
#
@command.seeds_block&.call(pipeline)
##
2019-10-12 21:52:04 +05:30
# Gather all runtime build/stage errors
2018-05-09 12:01:36 +05:30
#
2019-10-12 21:52:04 +05:30
if seeds_errors = pipeline.stage_seeds.flat_map(&:errors).compact.presence
2019-12-04 20:38:33 +05:30
return error(seeds_errors.join("\n"), config_error: true)
2018-05-09 12:01:36 +05:30
end
2019-10-12 21:52:04 +05:30
##
# Populate pipeline with all stages, and stages with builds.
#
pipeline.stages = pipeline.stage_seeds.map(&:to_resource)
2018-05-09 12:01:36 +05:30
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