summaryrefslogtreecommitdiff
path: root/lib/gitlab/ci/pipeline/seed/build.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/ci/pipeline/seed/build.rb')
-rw-r--r--lib/gitlab/ci/pipeline/seed/build.rb36
1 files changed, 28 insertions, 8 deletions
diff --git a/lib/gitlab/ci/pipeline/seed/build.rb b/lib/gitlab/ci/pipeline/seed/build.rb
index 299b27a5f13..54d92745992 100644
--- a/lib/gitlab/ci/pipeline/seed/build.rb
+++ b/lib/gitlab/ci/pipeline/seed/build.rb
@@ -11,11 +11,16 @@ module Gitlab
delegate :dig, to: :@seed_attributes
- def initialize(context, attributes, previous_stages)
+ def initialize(context, attributes, previous_stages, current_stage)
@context = context
@pipeline = context.pipeline
@seed_attributes = attributes
- @previous_stages = previous_stages
+ @stages_for_needs_lookup = if Feature.enabled?(:ci_same_stage_job_needs, @pipeline.project, default_enabled: :yaml)
+ (previous_stages + [current_stage]).compact
+ else
+ previous_stages
+ end
+
@needs_attributes = dig(:needs_attributes)
@resource_group_key = attributes.delete(:resource_group_key)
@job_variables = @seed_attributes.delete(:job_variables)
@@ -67,6 +72,7 @@ module Gitlab
.deep_merge(rules_attributes)
.deep_merge(allow_failure_criteria_attributes)
.deep_merge(@cache.cache_attributes)
+ .deep_merge(runner_tags)
end
def bridge?
@@ -148,14 +154,18 @@ module Gitlab
@needs_attributes.flat_map do |need|
next if need[:optional]
- result = @previous_stages.any? do |stage|
- stage.seeds_names.include?(need[:name])
- end
+ result = need_present?(need)
- "'#{name}' job needs '#{need[:name]}' job, but it was not added to the pipeline" unless result
+ "'#{name}' job needs '#{need[:name]}' job, but '#{need[:name]}' is not in any previous stage" unless result
end.compact
end
+ def need_present?(need)
+ @stages_for_needs_lookup.any? do |stage|
+ stage.seeds_names.include?(need[:name])
+ end
+ end
+
def max_needs_allowed
@pipeline.project.actual_limits.ci_needs_size_limit
end
@@ -202,6 +212,16 @@ module Gitlab
end
end
+ def runner_tags
+ { tag_list: evaluate_runner_tags }.compact
+ end
+
+ def evaluate_runner_tags
+ @seed_attributes[:tag_list]&.map do |tag|
+ ExpandVariables.expand_existing(tag, evaluate_context.variables)
+ end
+ end
+
# If a job uses `allow_failure:exit_codes` and `rules:allow_failure`
# we need to prevent the exit codes from being persisted because they
# would break the behavior defined by `rules:allow_failure`.
@@ -213,8 +233,6 @@ module Gitlab
end
def recalculate_yaml_variables!
- return unless ::Feature.enabled?(:ci_workflow_rules_variables, @pipeline.project, default_enabled: :yaml)
-
@seed_attributes[:yaml_variables] = Gitlab::Ci::Variables::Helpers.inherit_yaml_variables(
from: @context.root_variables, to: @job_variables, inheritance: @root_variables_inheritance
)
@@ -224,3 +242,5 @@ module Gitlab
end
end
end
+
+Gitlab::Ci::Pipeline::Seed::Build.prepend_mod_with('Gitlab::Ci::Pipeline::Seed::Build')