summaryrefslogtreecommitdiff
path: root/lib/gitlab/ci/config
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-03-16 18:18:33 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-03-16 18:18:33 +0000
commitf64a639bcfa1fc2bc89ca7db268f594306edfd7c (patch)
treea2c3c2ebcc3b45e596949db485d6ed18ffaacfa1 /lib/gitlab/ci/config
parentbfbc3e0d6583ea1a91f627528bedc3d65ba4b10f (diff)
downloadgitlab-ce-f64a639bcfa1fc2bc89ca7db268f594306edfd7c.tar.gz
Add latest changes from gitlab-org/gitlab@13-10-stable-eev13.10.0-rc40
Diffstat (limited to 'lib/gitlab/ci/config')
-rw-r--r--lib/gitlab/ci/config/entry/bridge.rb12
-rw-r--r--lib/gitlab/ci/config/entry/cache.rb112
-rw-r--r--lib/gitlab/ci/config/entry/environment.rb11
-rw-r--r--lib/gitlab/ci/config/entry/need.rb23
-rw-r--r--lib/gitlab/ci/config/entry/product/parallel.rb14
5 files changed, 127 insertions, 45 deletions
diff --git a/lib/gitlab/ci/config/entry/bridge.rb b/lib/gitlab/ci/config/entry/bridge.rb
index e8e2eef281e..73742298628 100644
--- a/lib/gitlab/ci/config/entry/bridge.rb
+++ b/lib/gitlab/ci/config/entry/bridge.rb
@@ -12,7 +12,7 @@ module Gitlab
include ::Gitlab::Ci::Config::Entry::Processable
ALLOWED_WHEN = %w[on_success on_failure always manual].freeze
- ALLOWED_KEYS = %i[trigger].freeze
+ ALLOWED_KEYS = %i[trigger parallel].freeze
validations do
validates :config, allowed_keys: ALLOWED_KEYS + PROCESSABLE_ALLOWED_KEYS
@@ -48,7 +48,12 @@ module Gitlab
inherit: false,
metadata: { allowed_needs: %i[job bridge] }
- attributes :when, :allow_failure
+ entry :parallel, Entry::Product::Parallel,
+ description: 'Parallel configuration for this job.',
+ inherit: false,
+ metadata: { allowed_strategies: %i(matrix) }
+
+ attributes :when, :allow_failure, :parallel
def self.matching?(name, config)
!name.to_s.start_with?('.') &&
@@ -66,7 +71,8 @@ module Gitlab
needs: (needs_value if needs_defined?),
ignore: ignored?,
when: self.when,
- scheduling_type: needs_defined? && !bridge_needs ? :dag : :stage
+ scheduling_type: needs_defined? && !bridge_needs ? :dag : :stage,
+ parallel: has_parallel? ? parallel_value : nil
).compact
end
diff --git a/lib/gitlab/ci/config/entry/cache.rb b/lib/gitlab/ci/config/entry/cache.rb
index 6b036182706..cf599ce5294 100644
--- a/lib/gitlab/ci/config/entry/cache.rb
+++ b/lib/gitlab/ci/config/entry/cache.rb
@@ -7,52 +7,90 @@ module Gitlab
##
# Entry that represents a cache configuration
#
- class Cache < ::Gitlab::Config::Entry::Node
- include ::Gitlab::Config::Entry::Configurable
- include ::Gitlab::Config::Entry::Validatable
- include ::Gitlab::Config::Entry::Attributable
-
- ALLOWED_KEYS = %i[key untracked paths when policy].freeze
- ALLOWED_POLICY = %w[pull-push push pull].freeze
- DEFAULT_POLICY = 'pull-push'
- ALLOWED_WHEN = %w[on_success on_failure always].freeze
- DEFAULT_WHEN = 'on_success'
-
- validations do
- validates :config, type: Hash, allowed_keys: ALLOWED_KEYS
- validates :policy,
- inclusion: { in: ALLOWED_POLICY, message: 'should be pull-push, push, or pull' },
- allow_blank: true
-
- with_options allow_nil: true do
- validates :when,
- inclusion: {
- in: ALLOWED_WHEN,
- message: 'should be on_success, on_failure or always'
- }
+ class Cache < ::Gitlab::Config::Entry::Simplifiable
+ strategy :Caches, if: -> (config) { Feature.enabled?(:multiple_cache_per_job) }
+ strategy :Cache, if: -> (config) { Feature.disabled?(:multiple_cache_per_job) }
+
+ class Caches < ::Gitlab::Config::Entry::ComposableArray
+ include ::Gitlab::Config::Entry::Validatable
+
+ MULTIPLE_CACHE_LIMIT = 4
+
+ validations do
+ validates :config, presence: true
+
+ validate do
+ unless config.is_a?(Hash) || config.is_a?(Array)
+ errors.add(:config, 'can only be a Hash or an Array')
+ end
+
+ if config.is_a?(Array) && config.count > MULTIPLE_CACHE_LIMIT
+ errors.add(:config, "no more than #{MULTIPLE_CACHE_LIMIT} caches can be created")
+ end
+ end
+ end
+
+ def initialize(*args)
+ super
+
+ @key = nil
+ end
+
+ def composable_class
+ Entry::Cache::Cache
end
end
- entry :key, Entry::Key,
- description: 'Cache key used to define a cache affinity.'
+ class Cache < ::Gitlab::Config::Entry::Node
+ include ::Gitlab::Config::Entry::Configurable
+ include ::Gitlab::Config::Entry::Validatable
+ include ::Gitlab::Config::Entry::Attributable
+
+ ALLOWED_KEYS = %i[key untracked paths when policy].freeze
+ ALLOWED_POLICY = %w[pull-push push pull].freeze
+ DEFAULT_POLICY = 'pull-push'
+ ALLOWED_WHEN = %w[on_success on_failure always].freeze
+ DEFAULT_WHEN = 'on_success'
+
+ validations do
+ validates :config, type: Hash, allowed_keys: ALLOWED_KEYS
+ validates :policy,
+ inclusion: { in: ALLOWED_POLICY, message: 'should be pull-push, push, or pull' },
+ allow_blank: true
+
+ with_options allow_nil: true do
+ validates :when,
+ inclusion: {
+ in: ALLOWED_WHEN,
+ message: 'should be on_success, on_failure or always'
+ }
+ end
+ end
- entry :untracked, ::Gitlab::Config::Entry::Boolean,
- description: 'Cache all untracked files.'
+ entry :key, Entry::Key,
+ description: 'Cache key used to define a cache affinity.'
- entry :paths, Entry::Paths,
- description: 'Specify which paths should be cached across builds.'
+ entry :untracked, ::Gitlab::Config::Entry::Boolean,
+ description: 'Cache all untracked files.'
- attributes :policy, :when
+ entry :paths, Entry::Paths,
+ description: 'Specify which paths should be cached across builds.'
- def value
- result = super
+ attributes :policy, :when
- result[:key] = key_value
- result[:policy] = policy || DEFAULT_POLICY
- # Use self.when to avoid conflict with reserved word
- result[:when] = self.when || DEFAULT_WHEN
+ def value
+ result = super
+
+ result[:key] = key_value
+ result[:policy] = policy || DEFAULT_POLICY
+ # Use self.when to avoid conflict with reserved word
+ result[:when] = self.when || DEFAULT_WHEN
+
+ result
+ end
+ end
- result
+ class UnknownStrategy < ::Gitlab::Config::Entry::Node
end
end
end
diff --git a/lib/gitlab/ci/config/entry/environment.rb b/lib/gitlab/ci/config/entry/environment.rb
index 64e6d48133f..2066e9be3b1 100644
--- a/lib/gitlab/ci/config/entry/environment.rb
+++ b/lib/gitlab/ci/config/entry/environment.rb
@@ -10,7 +10,7 @@ module Gitlab
class Environment < ::Gitlab::Config::Entry::Node
include ::Gitlab::Config::Entry::Configurable
- ALLOWED_KEYS = %i[name url action on_stop auto_stop_in kubernetes].freeze
+ ALLOWED_KEYS = %i[name url action on_stop auto_stop_in kubernetes deployment_tier].freeze
entry :kubernetes, Entry::Kubernetes, description: 'Kubernetes deployment configuration.'
@@ -47,6 +47,11 @@ module Gitlab
inclusion: { in: %w[start stop prepare], message: 'should be start, stop or prepare' },
allow_nil: true
+ validates :deployment_tier,
+ type: String,
+ inclusion: { in: ::Environment.tiers.keys, message: "must be one of #{::Environment.tiers.keys.join(', ')}" },
+ allow_nil: true
+
validates :on_stop, type: String, allow_nil: true
validates :kubernetes, type: Hash, allow_nil: true
validates :auto_stop_in, duration: true, allow_nil: true
@@ -85,6 +90,10 @@ module Gitlab
value[:auto_stop_in]
end
+ def deployment_tier
+ value[:deployment_tier]
+ end
+
def value
case @config
when String then { name: @config, action: 'start' }
diff --git a/lib/gitlab/ci/config/entry/need.rb b/lib/gitlab/ci/config/entry/need.rb
index 46191eca842..b3cf0f9e0fd 100644
--- a/lib/gitlab/ci/config/entry/need.rb
+++ b/lib/gitlab/ci/config/entry/need.rb
@@ -35,7 +35,14 @@ module Gitlab
end
def value
- { name: @config, artifacts: true }
+ if ::Feature.enabled?(:ci_needs_optional, default_enabled: :yaml)
+ { name: @config,
+ artifacts: true,
+ optional: false }
+ else
+ { name: @config,
+ artifacts: true }
+ end
end
end
@@ -43,14 +50,15 @@ module Gitlab
include ::Gitlab::Config::Entry::Validatable
include ::Gitlab::Config::Entry::Attributable
- ALLOWED_KEYS = %i[job artifacts].freeze
- attributes :job, :artifacts
+ ALLOWED_KEYS = %i[job artifacts optional].freeze
+ attributes :job, :artifacts, :optional
validations do
validates :config, presence: true
validates :config, allowed_keys: ALLOWED_KEYS
validates :job, type: String, presence: true
validates :artifacts, boolean: true, allow_nil: true
+ validates :optional, boolean: true, allow_nil: true
end
def type
@@ -58,7 +66,14 @@ module Gitlab
end
def value
- { name: job, artifacts: artifacts || artifacts.nil? }
+ if ::Feature.enabled?(:ci_needs_optional, default_enabled: :yaml)
+ { name: job,
+ artifacts: artifacts || artifacts.nil?,
+ optional: !!optional }
+ else
+ { name: job,
+ artifacts: artifacts || artifacts.nil? }
+ end
end
end
diff --git a/lib/gitlab/ci/config/entry/product/parallel.rb b/lib/gitlab/ci/config/entry/product/parallel.rb
index cd9eabbbc66..5c78a8f68c7 100644
--- a/lib/gitlab/ci/config/entry/product/parallel.rb
+++ b/lib/gitlab/ci/config/entry/product/parallel.rb
@@ -22,6 +22,13 @@ module Gitlab
greater_than_or_equal_to: 2,
less_than_or_equal_to: Entry::Product::Parallel::PARALLEL_LIMIT },
allow_nil: true
+
+ validate do
+ next unless opt(:allowed_strategies)
+ next if opt(:allowed_strategies).include?(:numeric)
+
+ errors.add(:config, 'cannot use "parallel: <number>".')
+ end
end
def value
@@ -38,6 +45,13 @@ module Gitlab
validations do
validates :config, allowed_keys: PERMITTED_KEYS
validates :config, required_keys: PERMITTED_KEYS
+
+ validate do
+ next unless opt(:allowed_strategies)
+ next if opt(:allowed_strategies).include?(:matrix)
+
+ errors.add(:config, 'cannot use "parallel: matrix".')
+ end
end
entry :matrix, Entry::Product::Matrix,