2019-12-26 22:10:19 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Ci
|
|
|
|
module Pipeline
|
|
|
|
module Chain
|
|
|
|
class Seed < Chain::Base
|
|
|
|
include Chain::Helpers
|
|
|
|
include Gitlab::Utils::StrongMemoize
|
|
|
|
|
|
|
|
def perform!
|
2020-11-24 15:15:51 +05:30
|
|
|
raise ArgumentError, 'missing YAML processor result' unless @command.yaml_processor_result
|
2019-12-26 22:10:19 +05:30
|
|
|
|
2021-04-29 21:17:54 +05:30
|
|
|
if ::Feature.enabled?(:ci_workflow_rules_variables, pipeline.project, default_enabled: :yaml)
|
|
|
|
raise ArgumentError, 'missing workflow rules result' unless @command.workflow_rules_result
|
|
|
|
end
|
|
|
|
|
2019-12-26 22:10:19 +05:30
|
|
|
# Allocate next IID. This operation must be outside of transactions of pipeline creations.
|
|
|
|
pipeline.ensure_project_iid!
|
2020-06-23 00:09:42 +05:30
|
|
|
pipeline.ensure_ci_ref!
|
2019-12-26 22:10:19 +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?
|
|
|
|
|
|
|
|
##
|
|
|
|
# Gather all runtime build/stage errors
|
|
|
|
#
|
2021-02-22 17:27:13 +05:30
|
|
|
if pipeline_seed.errors
|
|
|
|
return error(pipeline_seed.errors.join("\n"), config_error: true)
|
2019-12-26 22:10:19 +05:30
|
|
|
end
|
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
@command.pipeline_seed = pipeline_seed
|
2019-12-26 22:10:19 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def break?
|
|
|
|
pipeline.errors.any?
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2021-02-22 17:27:13 +05:30
|
|
|
def pipeline_seed
|
|
|
|
strong_memoize(:pipeline_seed) do
|
|
|
|
stages_attributes = @command.yaml_processor_result.stages_attributes
|
2021-04-29 21:17:54 +05:30
|
|
|
Gitlab::Ci::Pipeline::Seed::Pipeline.new(context, stages_attributes)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def context
|
|
|
|
Gitlab::Ci::Pipeline::Seed::Context.new(pipeline, root_variables: root_variables)
|
|
|
|
end
|
|
|
|
|
|
|
|
def root_variables
|
|
|
|
if ::Feature.enabled?(:ci_workflow_rules_variables, pipeline.project, default_enabled: :yaml)
|
|
|
|
::Gitlab::Ci::Variables::Helpers.merge_variables(
|
|
|
|
@command.yaml_processor_result.root_variables, @command.workflow_rules_result.variables
|
|
|
|
)
|
|
|
|
else
|
|
|
|
@command.yaml_processor_result.root_variables
|
2019-12-26 22:10:19 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|