diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-09-14 12:10:09 +0200 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-09-18 13:57:14 +0200 |
commit | dd784b1518501032e01e521adbf6ecf98d54ba55 (patch) | |
tree | 25d242d2f51efae8aa4d71702890c874d90f960b /lib | |
parent | 59f87e7317137c302f71eb6746262c1f4fee84d9 (diff) | |
download | gitlab-ce-dd784b1518501032e01e521adbf6ecf98d54ba55.tar.gz |
Use CI/CD job policy specification in YAML processor
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/ci/build/policy.rb | 19 | ||||
-rw-r--r-- | lib/gitlab/ci/build/policy/specification.rb | 3 | ||||
-rw-r--r-- | lib/gitlab/ci/yaml_processor.rb | 13 |
3 files changed, 26 insertions, 9 deletions
diff --git a/lib/gitlab/ci/build/policy.rb b/lib/gitlab/ci/build/policy.rb new file mode 100644 index 00000000000..6ab2f86c2e9 --- /dev/null +++ b/lib/gitlab/ci/build/policy.rb @@ -0,0 +1,19 @@ +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 diff --git a/lib/gitlab/ci/build/policy/specification.rb b/lib/gitlab/ci/build/policy/specification.rb index 0bb06ee8381..9ca3582b9b0 100644 --- a/lib/gitlab/ci/build/policy/specification.rb +++ b/lib/gitlab/ci/build/policy/specification.rb @@ -18,9 +18,6 @@ module Gitlab def satisfied_by?(pipeline, **metadata) raise NotImplementedError end - - def self.fabricate_all(*specs) - end end end end diff --git a/lib/gitlab/ci/yaml_processor.rb b/lib/gitlab/ci/yaml_processor.rb index 7582964b24e..44e616c01e5 100644 --- a/lib/gitlab/ci/yaml_processor.rb +++ b/lib/gitlab/ci/yaml_processor.rb @@ -89,13 +89,14 @@ module Gitlab builds.select do |build| 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_kubernetes && has_kubernetes, - except_kubernetes && !has_kubernetes].any? + only_specs = Gitlab::Ci::Build::Policy + .fabricate(job.fetch(:only, {})) + 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 |