summaryrefslogtreecommitdiff
path: root/lib/gitlab/ci/pipeline/seed/build.rb
diff options
context:
space:
mode:
authorKamil Trzciński <ayufan@ayufan.eu>2019-08-02 16:32:52 +0200
committerKamil Trzciński <ayufan@ayufan.eu>2019-08-02 18:41:40 +0200
commit684751d3c2233ee1ac33cf623e8b7822c60209d3 (patch)
tree5696d3f3e6a99a806ff185f3d9c11c22e50db92c /lib/gitlab/ci/pipeline/seed/build.rb
parent8156e77c1a25bc6050e5036fa3bbfd29201a6d5c (diff)
downloadgitlab-ce-684751d3c2233ee1ac33cf623e8b7822c60209d3.tar.gz
Make needs: to require previous jobsmake-needs-strong-connection
This changes `needs:` from weak reference to have a strong reference. This means that job will not be created unless all needs are present as part of a pipeline.
Diffstat (limited to 'lib/gitlab/ci/pipeline/seed/build.rb')
-rw-r--r--lib/gitlab/ci/pipeline/seed/build.rb31
1 files changed, 28 insertions, 3 deletions
diff --git a/lib/gitlab/ci/pipeline/seed/build.rb b/lib/gitlab/ci/pipeline/seed/build.rb
index d8296940a04..ab0d4c38ab6 100644
--- a/lib/gitlab/ci/pipeline/seed/build.rb
+++ b/lib/gitlab/ci/pipeline/seed/build.rb
@@ -9,9 +9,10 @@ module Gitlab
delegate :dig, to: :@attributes
- def initialize(pipeline, attributes)
+ def initialize(pipeline, attributes, previous_stages)
@pipeline = pipeline
@attributes = attributes
+ @previous_stages = previous_stages
@only = Gitlab::Ci::Build::Policy
.fabricate(attributes.delete(:only))
@@ -19,10 +20,15 @@ module Gitlab
.fabricate(attributes.delete(:except))
end
+ def name
+ dig(:name)
+ end
+
def included?
strong_memoize(:inclusion) do
- @only.all? { |spec| spec.satisfied_by?(@pipeline, self) } &&
- @except.none? { |spec| spec.satisfied_by?(@pipeline, self) }
+ all_of_only? &&
+ none_of_except? &&
+ all_of_needs?
end
end
@@ -42,6 +48,25 @@ module Gitlab
@attributes.to_h.dig(:options, :trigger).present?
end
+ def all_of_only?
+ @only.all? { |spec| spec.satisfied_by?(@pipeline, self) }
+ end
+
+ def none_of_except?
+ @except.none? { |spec| spec.satisfied_by?(@pipeline, self) }
+ end
+
+ def all_of_needs?
+ return true unless Feature.enabled?(:ci_dag_support, @pipeline.project)
+ return true if dig(:needs_attributes).nil?
+
+ dig(:needs_attributes).all? do |need|
+ @previous_stages.any? do |stage|
+ stage.seeds_names.include?(need[:name])
+ end
+ end
+ end
+
def to_resource
strong_memoize(:resource) do
if bridge?