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/config/entry')
-rw-r--r--lib/gitlab/ci/config/entry/allow_failure.rb31
-rw-r--r--lib/gitlab/ci/config/entry/bridge.rb7
-rw-r--r--lib/gitlab/ci/config/entry/job.rb29
-rw-r--r--lib/gitlab/ci/config/entry/need.rb38
-rw-r--r--lib/gitlab/ci/config/entry/needs.rb11
-rw-r--r--lib/gitlab/ci/config/entry/processable.rb7
-rw-r--r--lib/gitlab/ci/config/entry/root.rb1
-rw-r--r--lib/gitlab/ci/config/entry/rules/rule.rb6
-rw-r--r--lib/gitlab/ci/config/entry/variables.rb7
9 files changed, 126 insertions, 11 deletions
diff --git a/lib/gitlab/ci/config/entry/allow_failure.rb b/lib/gitlab/ci/config/entry/allow_failure.rb
new file mode 100644
index 00000000000..de768c3a03b
--- /dev/null
+++ b/lib/gitlab/ci/config/entry/allow_failure.rb
@@ -0,0 +1,31 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module Ci
+ class Config
+ module Entry
+ ##
+ # Entry that represents allow_failure settings.
+ #
+ class AllowFailure < ::Gitlab::Config::Entry::Node
+ include ::Gitlab::Config::Entry::Attributable
+ include ::Gitlab::Config::Entry::Validatable
+
+ ALLOWED_KEYS = %i[exit_codes].freeze
+ attributes ALLOWED_KEYS
+
+ validations do
+ validates :config, hash_or_boolean: true
+ validates :config, allowed_keys: ALLOWED_KEYS
+ validates :exit_codes, array_of_integers_or_integer: true, allow_nil: true
+ end
+
+ def value
+ @config[:exit_codes] = Array.wrap(exit_codes) if exit_codes.present?
+ @config
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/ci/config/entry/bridge.rb b/lib/gitlab/ci/config/entry/bridge.rb
index 70fcc1d586a..e8e2eef281e 100644
--- a/lib/gitlab/ci/config/entry/bridge.rb
+++ b/lib/gitlab/ci/config/entry/bridge.rb
@@ -22,6 +22,7 @@ module Gitlab
in: ALLOWED_WHEN,
message: "should be one of: #{ALLOWED_WHEN.join(', ')}"
}
+ validates :allow_failure, boolean: true
end
validate on: :composed do
@@ -47,7 +48,7 @@ module Gitlab
inherit: false,
metadata: { allowed_needs: %i[job bridge] }
- attributes :when
+ attributes :when, :allow_failure
def self.matching?(name, config)
!name.to_s.start_with?('.') &&
@@ -72,6 +73,10 @@ module Gitlab
def bridge_needs
needs_value[:bridge] if needs_value
end
+
+ def ignored?
+ allow_failure.nil? ? manual_action? : allow_failure
+ end
end
end
end
diff --git a/lib/gitlab/ci/config/entry/job.rb b/lib/gitlab/ci/config/entry/job.rb
index 1ce7060df22..85e3514499c 100644
--- a/lib/gitlab/ci/config/entry/job.rb
+++ b/lib/gitlab/ci/config/entry/job.rb
@@ -31,6 +31,7 @@ module Gitlab
validates :dependencies, array_of_strings: true
validates :resource_group, type: String
+ validates :allow_failure, hash_or_boolean: true
end
validates :start_in, duration: { limit: '1 week' }, if: :delayed?
@@ -117,9 +118,14 @@ module Gitlab
description: 'Parallel configuration for this job.',
inherit: false
+ entry :allow_failure, ::Gitlab::Ci::Config::Entry::AllowFailure,
+ description: 'Indicates whether this job is allowed to fail or not.',
+ inherit: false
+
attributes :script, :tags, :when, :dependencies,
:needs, :retry, :parallel, :start_in,
- :interruptible, :timeout, :resource_group, :release
+ :interruptible, :timeout, :resource_group,
+ :release, :allow_failure
def self.matching?(name, config)
!name.to_s.start_with?('.') &&
@@ -166,11 +172,32 @@ module Gitlab
release: release_value,
after_script: after_script_value,
ignore: ignored?,
+ allow_failure_criteria: allow_failure_criteria,
needs: needs_defined? ? needs_value : nil,
resource_group: resource_group,
scheduling_type: needs_defined? ? :dag : :stage
).compact
end
+
+ def ignored?
+ allow_failure_defined? ? static_allow_failure : manual_action?
+ end
+
+ private
+
+ def allow_failure_criteria
+ return unless ::Gitlab::Ci::Features.allow_failure_with_exit_codes_enabled?
+
+ if allow_failure_defined? && allow_failure_value.is_a?(Hash)
+ allow_failure_value
+ end
+ end
+
+ def static_allow_failure
+ return false if allow_failure_value.is_a?(Hash)
+
+ allow_failure_value
+ end
end
end
end
diff --git a/lib/gitlab/ci/config/entry/need.rb b/lib/gitlab/ci/config/entry/need.rb
index abfffb7a5ed..46191eca842 100644
--- a/lib/gitlab/ci/config/entry/need.rb
+++ b/lib/gitlab/ci/config/entry/need.rb
@@ -8,7 +8,19 @@ module Gitlab
strategy :JobString, if: -> (config) { config.is_a?(String) }
strategy :JobHash,
- if: -> (config) { config.is_a?(Hash) && config.key?(:job) && !(config.key?(:project) || config.key?(:ref)) }
+ if: -> (config) { config.is_a?(Hash) && same_pipeline_need?(config) }
+
+ strategy :CrossPipelineDependency,
+ if: -> (config) { config.is_a?(Hash) && cross_pipeline_need?(config) }
+
+ def self.same_pipeline_need?(config)
+ config.key?(:job) &&
+ !(config.key?(:project) || config.key?(:ref) || config.key?(:pipeline))
+ end
+
+ def self.cross_pipeline_need?(config)
+ config.key?(:job) && config.key?(:pipeline) && !config.key?(:project)
+ end
class JobString < ::Gitlab::Config::Entry::Node
include ::Gitlab::Config::Entry::Validatable
@@ -50,6 +62,30 @@ module Gitlab
end
end
+ class CrossPipelineDependency < ::Gitlab::Config::Entry::Node
+ include ::Gitlab::Config::Entry::Validatable
+ include ::Gitlab::Config::Entry::Attributable
+
+ ALLOWED_KEYS = %i[pipeline job artifacts].freeze
+ attributes :pipeline, :job, :artifacts
+
+ validations do
+ validates :config, presence: true
+ validates :config, allowed_keys: ALLOWED_KEYS
+ validates :pipeline, type: String, presence: true
+ validates :job, type: String, presence: true
+ validates :artifacts, boolean: true, allow_nil: true
+ end
+
+ def type
+ :cross_dependency
+ end
+
+ def value
+ super.merge(artifacts: artifacts || artifacts.nil?)
+ end
+ end
+
class UnknownStrategy < ::Gitlab::Config::Entry::Node
def type
end
diff --git a/lib/gitlab/ci/config/entry/needs.rb b/lib/gitlab/ci/config/entry/needs.rb
index 66cd57b8cf3..dd01cfeedff 100644
--- a/lib/gitlab/ci/config/entry/needs.rb
+++ b/lib/gitlab/ci/config/entry/needs.rb
@@ -10,6 +10,8 @@ module Gitlab
class Needs < ::Gitlab::Config::Entry::ComposableArray
include ::Gitlab::Config::Entry::Validatable
+ NEEDS_CROSS_PIPELINE_DEPENDENCIES_LIMIT = 5
+
validations do
validate do
unless config.is_a?(Hash) || config.is_a?(Array)
@@ -27,6 +29,15 @@ module Gitlab
errors.add(:config, "uses invalid types: #{extra_keys.join(', ')}")
end
end
+
+ validate on: :composed do
+ cross_dependencies = value[:cross_dependency].to_a
+ cross_pipeline_dependencies = cross_dependencies.select { |dep| dep[:pipeline] }
+
+ if cross_pipeline_dependencies.size > NEEDS_CROSS_PIPELINE_DEPENDENCIES_LIMIT
+ errors.add(:config, "must be less than or equal to #{NEEDS_CROSS_PIPELINE_DEPENDENCIES_LIMIT}")
+ end
+ end
end
def value
diff --git a/lib/gitlab/ci/config/entry/processable.rb b/lib/gitlab/ci/config/entry/processable.rb
index c0315e5f901..5ef8cfbddb7 100644
--- a/lib/gitlab/ci/config/entry/processable.rb
+++ b/lib/gitlab/ci/config/entry/processable.rb
@@ -32,7 +32,6 @@ module Gitlab
with_options allow_nil: true do
validates :extends, array_of_strings_or_string: true
validates :rules, array_of_hashes: true
- validates :allow_failure, boolean: true
end
end
@@ -65,7 +64,7 @@ module Gitlab
inherit: false,
default: {}
- attributes :extends, :rules, :allow_failure
+ attributes :extends, :rules
end
def compose!(deps = nil)
@@ -141,10 +140,6 @@ module Gitlab
def manual_action?
self.when == 'manual'
end
-
- def ignored?
- allow_failure.nil? ? manual_action? : allow_failure
- end
end
end
end
diff --git a/lib/gitlab/ci/config/entry/root.rb b/lib/gitlab/ci/config/entry/root.rb
index 2d93f1ab06e..54ef84b965a 100644
--- a/lib/gitlab/ci/config/entry/root.rb
+++ b/lib/gitlab/ci/config/entry/root.rb
@@ -50,6 +50,7 @@ module Gitlab
entry :variables, Entry::Variables,
description: 'Environment variables that will be used.',
+ metadata: { use_value_data: true },
reserved: true
entry :stages, Entry::Stages,
diff --git a/lib/gitlab/ci/config/entry/rules/rule.rb b/lib/gitlab/ci/config/entry/rules/rule.rb
index 8ffd49b8a93..840f2d6f31a 100644
--- a/lib/gitlab/ci/config/entry/rules/rule.rb
+++ b/lib/gitlab/ci/config/entry/rules/rule.rb
@@ -6,14 +6,18 @@ module Gitlab
module Entry
class Rules::Rule < ::Gitlab::Config::Entry::Node
include ::Gitlab::Config::Entry::Validatable
+ include ::Gitlab::Config::Entry::Configurable
include ::Gitlab::Config::Entry::Attributable
CLAUSES = %i[if changes exists].freeze
- ALLOWED_KEYS = %i[if changes exists when start_in allow_failure].freeze
+ ALLOWED_KEYS = %i[if changes exists when start_in allow_failure variables].freeze
ALLOWABLE_WHEN = %w[on_success on_failure always never manual delayed].freeze
attributes :if, :changes, :exists, :when, :start_in, :allow_failure
+ entry :variables, Entry::Variables,
+ description: 'Environment variables to define for rule conditions.'
+
validations do
validates :config, presence: true
validates :config, type: { with: Hash }
diff --git a/lib/gitlab/ci/config/entry/variables.rb b/lib/gitlab/ci/config/entry/variables.rb
index e258f7128fc..dc164d752be 100644
--- a/lib/gitlab/ci/config/entry/variables.rb
+++ b/lib/gitlab/ci/config/entry/variables.rb
@@ -13,7 +13,8 @@ module Gitlab
ALLOWED_VALUE_DATA = %i[value description].freeze
validations do
- validates :config, variables: { allowed_value_data: ALLOWED_VALUE_DATA }
+ validates :config, variables: { allowed_value_data: ALLOWED_VALUE_DATA }, if: :use_value_data?
+ validates :config, variables: true, unless: :use_value_data?
end
def value
@@ -28,6 +29,10 @@ module Gitlab
Hash[@config.map { |key, value| [key.to_s, expand_value(value)] }]
end
+ def use_value_data?
+ opt(:use_value_data)
+ end
+
private
def expand_value(value)