summaryrefslogtreecommitdiff
path: root/lib/gitlab/ci/variables
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-09-20 13:18:24 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-09-20 13:18:24 +0000
commit0653e08efd039a5905f3fa4f6e9cef9f5d2f799c (patch)
tree4dcc884cf6d81db44adae4aa99f8ec1233a41f55 /lib/gitlab/ci/variables
parent744144d28e3e7fddc117924fef88de5d9674fe4c (diff)
downloadgitlab-ce-0653e08efd039a5905f3fa4f6e9cef9f5d2f799c.tar.gz
Add latest changes from gitlab-org/gitlab@14-3-stable-eev14.3.0-rc42
Diffstat (limited to 'lib/gitlab/ci/variables')
-rw-r--r--lib/gitlab/ci/variables/collection.rb15
-rw-r--r--lib/gitlab/ci/variables/collection/sort.rb2
2 files changed, 11 insertions, 6 deletions
diff --git a/lib/gitlab/ci/variables/collection.rb b/lib/gitlab/ci/variables/collection.rb
index ef9ba1b73c7..09c75a2b3f1 100644
--- a/lib/gitlab/ci/variables/collection.rb
+++ b/lib/gitlab/ci/variables/collection.rb
@@ -10,7 +10,7 @@ module Gitlab
def initialize(variables = [], errors = nil)
@variables = []
- @variables_by_key = {}
+ @variables_by_key = Hash.new { |h, k| h[k] = [] }
@errors = errors
variables.each { |variable| self.append(variable) }
@@ -19,7 +19,7 @@ module Gitlab
def append(resource)
item = Collection::Item.fabricate(resource)
@variables.append(item)
- @variables_by_key[item[:key]] = item
+ @variables_by_key[item[:key]] << item
self
end
@@ -46,7 +46,12 @@ module Gitlab
end
def [](key)
- @variables_by_key[key]
+ all(key)&.last
+ end
+
+ def all(key)
+ vars = @variables_by_key[key]
+ vars unless vars.empty?
end
def size
@@ -72,7 +77,7 @@ module Gitlab
match = Regexp.last_match
if match[:key]
# we matched variable
- if variable = @variables_by_key[match[:key]]
+ if variable = self[match[:key]]
variable.value
elsif keep_undefined
match[0]
@@ -85,7 +90,7 @@ module Gitlab
end
def sort_and_expand_all(project, keep_undefined: false)
- return self if Feature.disabled?(:variable_inside_variable, project)
+ return self if Feature.disabled?(:variable_inside_variable, project, default_enabled: :yaml)
sorted = Sort.new(self)
return self.class.new(self, sorted.errors) unless sorted.valid?
diff --git a/lib/gitlab/ci/variables/collection/sort.rb b/lib/gitlab/ci/variables/collection/sort.rb
index 90a929b8a07..62637825c15 100644
--- a/lib/gitlab/ci/variables/collection/sort.rb
+++ b/lib/gitlab/ci/variables/collection/sort.rb
@@ -42,7 +42,7 @@ module Gitlab
depends_on = var_item.depends_on
return unless depends_on
- depends_on.filter_map { |var_ref_name| @collection[var_ref_name] }.each(&block)
+ depends_on.filter_map { |var_ref_name| @collection.all(var_ref_name) }.flatten.each(&block)
end
end
end