BigW Consortium Gitlab

Commit dd784b15 by Grzegorz Bizon

Use CI/CD job policy specification in YAML processor

parent 59f87e73
module Gitlab
module Ci
module Build
module Policy
def self.fabricate(specs)
specifications = specs.to_h.map do |spec, value|
begin
self.const_get(spec.to_s.camelize).new(value)
rescue NameError
next
end
end
specifications.compact
end
end
end
end
end
...@@ -18,9 +18,6 @@ module Gitlab ...@@ -18,9 +18,6 @@ module Gitlab
def satisfied_by?(pipeline, **metadata) def satisfied_by?(pipeline, **metadata)
raise NotImplementedError raise NotImplementedError
end end
def self.fabricate_all(*specs)
end
end end
end end
end end
......
...@@ -89,13 +89,14 @@ module Gitlab ...@@ -89,13 +89,14 @@ module Gitlab
builds.select do |build| builds.select do |build|
job = @jobs[build.fetch(:name).to_sym] job = @jobs[build.fetch(:name).to_sym]
has_kubernetes = pipeline.has_kubernetes_active?
only_kubernetes = job.dig(:only, :kubernetes)
except_kubernetes = job.dig(:except, :kubernetes)
[!only_kubernetes && !except_kubernetes, only_specs = Gitlab::Ci::Build::Policy
only_kubernetes && has_kubernetes, .fabricate(job.fetch(:only, {}))
except_kubernetes && !has_kubernetes].any? except_specs = Gitlab::Ci::Build::Policy
.fabricate(job.fetch(:except, {}))
only_specs.all? { |spec| spec.satisfied_by?(pipeline) } &&
except_specs.none? { |spec| spec.satisfied_by?(pipeline) }
end end
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment