diff options
author | Shinya Maeda <shinya@gitlab.com> | 2018-12-04 21:30:57 +0900 |
---|---|---|
committer | Shinya Maeda <shinya@gitlab.com> | 2018-12-05 00:11:48 +0900 |
commit | ad957a3f4293febe26f069e7f96c65ba86f48aa8 (patch) | |
tree | 339a4ca0c1564a37c1845d1c0eb5dec48e33d73d /lib | |
parent | 2b2f93698b4f479d673067caa384b604732852e4 (diff) | |
download | gitlab-ce-ad957a3f4293febe26f069e7f96c65ba86f48aa8.tar.gz |
Define the default value for only/except policies
Currently, if a job does not have only/except policies, the policy is considered as an unspecified state, and therefore the job is executed regardless of how it's executed and which branch/tags are targetted.
Ideally, this should be specified as only: ['branches', 'tags'], as it indicates that unspecified policy jobs are meant to run on any git references.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/ci/config/entry/except_policy.rb | 17 | ||||
-rw-r--r-- | lib/gitlab/ci/config/entry/job.rb | 4 | ||||
-rw-r--r-- | lib/gitlab/ci/config/entry/only_policy.rb | 18 | ||||
-rw-r--r-- | lib/gitlab/ci/config/entry/policy.rb | 15 |
4 files changed, 48 insertions, 6 deletions
diff --git a/lib/gitlab/ci/config/entry/except_policy.rb b/lib/gitlab/ci/config/entry/except_policy.rb new file mode 100644 index 00000000000..46ded35325d --- /dev/null +++ b/lib/gitlab/ci/config/entry/except_policy.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +module Gitlab + module Ci + class Config + module Entry + ## + # Entry that represents an only/except trigger policy for the job. + # + class ExceptPolicy < Policy + def self.default + end + end + end + end + end +end diff --git a/lib/gitlab/ci/config/entry/job.rb b/lib/gitlab/ci/config/entry/job.rb index 4f2ac94b6c3..085be5da08d 100644 --- a/lib/gitlab/ci/config/entry/job.rb +++ b/lib/gitlab/ci/config/entry/job.rb @@ -65,10 +65,10 @@ module Gitlab entry :services, Entry::Services, description: 'Services that will be used to execute this job.' - entry :only, Entry::Policy, + entry :only, Entry::OnlyPolicy, description: 'Refs policy this job will be executed for.' - entry :except, Entry::Policy, + entry :except, Entry::ExceptPolicy, description: 'Refs policy this job will be executed for.' entry :variables, Entry::Variables, diff --git a/lib/gitlab/ci/config/entry/only_policy.rb b/lib/gitlab/ci/config/entry/only_policy.rb new file mode 100644 index 00000000000..9a581b8e97e --- /dev/null +++ b/lib/gitlab/ci/config/entry/only_policy.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true + +module Gitlab + module Ci + class Config + module Entry + ## + # Entry that represents an only/except trigger policy for the job. + # + class OnlyPolicy < Policy + def self.default + { refs: %w[branches tags] } + end + end + end + end + end +end diff --git a/lib/gitlab/ci/config/entry/policy.rb b/lib/gitlab/ci/config/entry/policy.rb index 998da1f6837..81e74a639fc 100644 --- a/lib/gitlab/ci/config/entry/policy.rb +++ b/lib/gitlab/ci/config/entry/policy.rb @@ -5,12 +5,9 @@ module Gitlab class Config module Entry ## - # Entry that represents an only/except trigger policy for the job. + # Base class for OnlyPolicy and ExceptPolicy # class Policy < ::Gitlab::Config::Entry::Simplifiable - strategy :RefsPolicy, if: -> (config) { config.is_a?(Array) } - strategy :ComplexPolicy, if: -> (config) { config.is_a?(Hash) } - class RefsPolicy < ::Gitlab::Config::Entry::Node include ::Gitlab::Config::Entry::Validatable @@ -66,6 +63,16 @@ module Gitlab def self.default end + + ## + # Class-level execution won't be inherited by subclasses by default. + # Therefore, we need to explicitly execute that for OnlyPolicy and ExceptPolicy + def self.inherited(klass) + super + + klass.strategy :RefsPolicy, if: -> (config) { config.is_a?(Array) } + klass.strategy :ComplexPolicy, if: -> (config) { config.is_a?(Hash) } + end end end end |