diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-08-26 12:45:36 +0200 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2017-08-26 12:45:36 +0200 |
commit | 326dc7da3bb7e6537095277dc8ee8ae880774b62 (patch) | |
tree | a7975f8850f5cef9fc706de3a05a7bbd49f8da82 /lib | |
parent | ae99f74b77fc0f49a9efd5f71119e7de4e313629 (diff) | |
download | gitlab-ce-326dc7da3bb7e6537095277dc8ee8ae880774b62.tar.gz |
Check if kubernetes required before creating a job
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ci/gitlab_ci_yaml_processor.rb | 19 | ||||
-rw-r--r-- | lib/gitlab/ci/config/entry/policy.rb | 11 |
2 files changed, 22 insertions, 8 deletions
diff --git a/lib/ci/gitlab_ci_yaml_processor.rb b/lib/ci/gitlab_ci_yaml_processor.rb index 3efd9b3bdac..72a38e97648 100644 --- a/lib/ci/gitlab_ci_yaml_processor.rb +++ b/lib/ci/gitlab_ci_yaml_processor.rb @@ -44,6 +44,22 @@ module Ci end end + def pipeline_stage_builds(stage, pipeline) + builds = builds_for_stage_and_ref( + stage, pipeline.ref, pipeline.tag?, pipeline.source) + + builds.select do |build| + job = @jobs[build.fetch(:name).to_sym] + has_kubernetes = pipeline.has_kubernetes_available? + 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? + end + end + def builds @jobs.map do |name, _| build_attributes(name) @@ -52,8 +68,7 @@ module Ci def stage_seeds(pipeline) seeds = @stages.uniq.map do |stage| - builds = builds_for_stage_and_ref( - stage, pipeline.ref, pipeline.tag?, pipeline.source) + builds = pipeline_stage_builds(stage, pipeline) Gitlab::Ci::Stage::Seed.new(pipeline, stage, builds) if builds.any? end diff --git a/lib/gitlab/ci/config/entry/policy.rb b/lib/gitlab/ci/config/entry/policy.rb index bcb76de65b2..a8bba3d3ea4 100644 --- a/lib/gitlab/ci/config/entry/policy.rb +++ b/lib/gitlab/ci/config/entry/policy.rb @@ -7,7 +7,7 @@ module Gitlab # class Policy < Simplifiable strategy :RefsPolicy, if: -> (config) { config.is_a?(Array) } - strategy :ExpressionsPolicy, if: -> (config) { config.is_a?(Hash) } + strategy :ComplexPolicy, if: -> (config) { config.is_a?(Hash) } class RefsPolicy < Entry::Node include Entry::Validatable @@ -21,20 +21,19 @@ module Gitlab end end - class ExpressionsPolicy < Entry::Node + class ComplexPolicy < Entry::Node include Entry::Validatable include Entry::Attributable - attributes :refs, :expressions + attributes :refs, :kubernetes validations do validates :config, presence: true - validates :config, allowed_keys: %i[refs expressions] + validates :config, allowed_keys: %i[refs kubernetes] with_options allow_nil: true do validates :refs, array_of_strings_or_regexps: true - validates :expressions, type: Array - validates :expressions, presence: true + validates :kubernetes, inclusion: { in: [true] } end end end |