Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/ci/yaml_processor.rb')
-rw-r--r--lib/gitlab/ci/yaml_processor.rb28
1 files changed, 21 insertions, 7 deletions
diff --git a/lib/gitlab/ci/yaml_processor.rb b/lib/gitlab/ci/yaml_processor.rb
index 6f1ab79064a..7f3f518dfd7 100644
--- a/lib/gitlab/ci/yaml_processor.rb
+++ b/lib/gitlab/ci/yaml_processor.rb
@@ -9,6 +9,12 @@ module Gitlab
attr_reader :stages, :jobs
+ ResultWithErrors = Struct.new(:content, :errors) do
+ def valid?
+ errors.empty?
+ end
+ end
+
def initialize(config, opts = {})
@ci_config = Gitlab::Ci::Config.new(config, **opts)
@config = @ci_config.to_hash
@@ -22,6 +28,18 @@ module Gitlab
raise ValidationError, e.message
end
+ def self.new_with_validation_errors(content, opts = {})
+ return ResultWithErrors.new('', ['Please provide content of .gitlab-ci.yml']) if content.blank?
+
+ config = Gitlab::Ci::Config.new(content, **opts)
+ return ResultWithErrors.new("", config.errors) unless config.valid?
+
+ config = Gitlab::Ci::YamlProcessor.new(content, opts)
+ ResultWithErrors.new(config, [])
+ rescue ValidationError, Gitlab::Ci::Config::ConfigError => e
+ ResultWithErrors.new('', [e.message])
+ end
+
def builds
@jobs.map do |name, _|
build_attributes(name)
@@ -42,6 +60,8 @@ module Gitlab
yaml_variables: transform_to_yaml_variables(job_variables(name)),
needs_attributes: job.dig(:needs, :job),
interruptible: job[:interruptible],
+ only: job[:only],
+ except: job[:except],
rules: job[:rules],
cache: job[:cache],
resource_group_key: job[:resource_group],
@@ -72,13 +92,7 @@ module Gitlab
def stages_attributes
@stages.uniq.map do |stage|
- seeds = stage_builds_attributes(stage).map do |attributes|
- job = @jobs.fetch(attributes[:name].to_sym)
-
- attributes
- .merge(only: job.fetch(:only, {}))
- .merge(except: job.fetch(:except, {}))
- end
+ seeds = stage_builds_attributes(stage)
{ name: stage, index: @stages.index(stage), builds: seeds }
end