diff options
Diffstat (limited to 'lib/gitlab/ci/config')
-rw-r--r-- | lib/gitlab/ci/config/entry/default.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/ci/config/entry/job.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/ci/config/entry/processable.rb | 3 | ||||
-rw-r--r-- | lib/gitlab/ci/config/entry/tags.rb | 30 |
4 files changed, 34 insertions, 3 deletions
diff --git a/lib/gitlab/ci/config/entry/default.rb b/lib/gitlab/ci/config/entry/default.rb index eaaf9f69102..145772c7a92 100644 --- a/lib/gitlab/ci/config/entry/default.rb +++ b/lib/gitlab/ci/config/entry/default.rb @@ -53,7 +53,7 @@ module Gitlab description: 'Set retry default value.', inherit: false - entry :tags, ::Gitlab::Config::Entry::ArrayOfStrings, + entry :tags, Entry::Tags, description: 'Set the default tags.', inherit: false diff --git a/lib/gitlab/ci/config/entry/job.rb b/lib/gitlab/ci/config/entry/job.rb index bd4d5f33689..f867189d521 100644 --- a/lib/gitlab/ci/config/entry/job.rb +++ b/lib/gitlab/ci/config/entry/job.rb @@ -85,7 +85,7 @@ module Gitlab description: 'Retry configuration for this job.', inherit: true - entry :tags, ::Gitlab::Config::Entry::ArrayOfStrings, + entry :tags, Entry::Tags, description: 'Set the tags.', inherit: true diff --git a/lib/gitlab/ci/config/entry/processable.rb b/lib/gitlab/ci/config/entry/processable.rb index 3543b5493bd..2549c35ebd6 100644 --- a/lib/gitlab/ci/config/entry/processable.rb +++ b/lib/gitlab/ci/config/entry/processable.rb @@ -16,6 +16,7 @@ module Gitlab PROCESSABLE_ALLOWED_KEYS = %i[extends stage only except rules variables inherit allow_failure when needs resource_group].freeze + MAX_NESTING_LEVEL = 10 included do validations do @@ -31,7 +32,7 @@ module Gitlab with_options allow_nil: true do validates :extends, array_of_strings_or_string: true - validates :rules, nested_array_of_hashes: true + validates :rules, nested_array_of_hashes_or_arrays: { max_level: MAX_NESTING_LEVEL } validates :resource_group, type: String end end diff --git a/lib/gitlab/ci/config/entry/tags.rb b/lib/gitlab/ci/config/entry/tags.rb new file mode 100644 index 00000000000..ca3b48372e2 --- /dev/null +++ b/lib/gitlab/ci/config/entry/tags.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +module Gitlab + module Ci + class Config + module Entry + ## + # Entry that represents an array of tags. + # + class Tags < ::Gitlab::Config::Entry::Node + include ::Gitlab::Config::Entry::Validatable + + TAGS_LIMIT = 50 + + validations do + validates :config, array_of_strings: true + + validate do + next unless ::Feature.enabled?(:ci_build_tags_limit, default_enabled: :yaml) + + if config.is_a?(Array) && config.size >= TAGS_LIMIT + errors.add(:config, _("must be less than the limit of %{tag_limit} tags") % { tag_limit: TAGS_LIMIT }) + end + end + end + end + end + end + end +end |