diff options
author | drew <dscimino@gmail.com> | 2019-09-09 13:21:26 +0000 |
---|---|---|
committer | Kamil TrzciĆski <ayufan@ayufan.eu> | 2019-09-09 13:21:26 +0000 |
commit | 9458192f2bc17928ba775ac0c57b791a8e0aad27 (patch) | |
tree | 2dcd09f2cc6faeb382118e5294de17f9031d8d4f /lib | |
parent | ee5bd24418fa9a7dca645a414be28ef4f8d8232b (diff) | |
download | gitlab-ce-9458192f2bc17928ba775ac0c57b791a8e0aad27.tar.gz |
Passing job:rules downstream and E2E specs for job:rules configuration
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/ci/build/rules.rb | 9 | ||||
-rw-r--r-- | lib/gitlab/ci/build/rules/rule/clause.rb | 4 | ||||
-rw-r--r-- | lib/gitlab/ci/config/entry/job.rb | 10 | ||||
-rw-r--r-- | lib/gitlab/ci/config/entry/rules.rb | 4 | ||||
-rw-r--r-- | lib/gitlab/ci/pipeline/seed/build.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/ci/yaml_processor.rb | 1 |
6 files changed, 24 insertions, 6 deletions
diff --git a/lib/gitlab/ci/build/rules.rb b/lib/gitlab/ci/build/rules.rb index 89623a809c9..43399c74457 100644 --- a/lib/gitlab/ci/build/rules.rb +++ b/lib/gitlab/ci/build/rules.rb @@ -6,7 +6,14 @@ module Gitlab class Rules include ::Gitlab::Utils::StrongMemoize - Result = Struct.new(:when, :start_in) + Result = Struct.new(:when, :start_in) do + def build_attributes + { + when: self.when, + options: { start_in: start_in }.compact + }.compact + end + end def initialize(rule_hashes, default_when = 'on_success') @rule_list = Rule.fabricate_list(rule_hashes) diff --git a/lib/gitlab/ci/build/rules/rule/clause.rb b/lib/gitlab/ci/build/rules/rule/clause.rb index ff0baf3348c..bf787fe95a6 100644 --- a/lib/gitlab/ci/build/rules/rule/clause.rb +++ b/lib/gitlab/ci/build/rules/rule/clause.rb @@ -13,9 +13,7 @@ module Gitlab UnknownClauseError = Class.new(StandardError) def self.fabricate(type, value) - type = type.to_s.camelize - - self.const_get(type).new(value) if self.const_defined?(type) + "#{self}::#{type.to_s.camelize}".safe_constantize&.new(value) end def initialize(spec) diff --git a/lib/gitlab/ci/config/entry/job.rb b/lib/gitlab/ci/config/entry/job.rb index 3009c7e8329..f750886a8c5 100644 --- a/lib/gitlab/ci/config/entry/job.rb +++ b/lib/gitlab/ci/config/entry/job.rb @@ -122,7 +122,7 @@ module Gitlab helpers :before_script, :script, :stage, :type, :after_script, :cache, :image, :services, :only, :except, :variables, - :artifacts, :environment, :coverage, :retry, + :artifacts, :environment, :coverage, :retry, :rules, :parallel, :needs, :interruptible attributes :script, :tags, :allow_failure, :when, :dependencies, @@ -145,6 +145,13 @@ module Gitlab end @entries.delete(:type) + + # This is something of a hack, see issue for details: + # https://gitlab.com/gitlab-org/gitlab-ce/issues/67150 + if !only_defined? && has_rules? + @entries.delete(:only) + @entries.delete(:except) + end end inherit!(deps) @@ -203,6 +210,7 @@ module Gitlab cache: cache_value, only: only_value, except: except_value, + rules: has_rules? ? rules_value : nil, variables: variables_defined? ? variables_value : {}, environment: environment_defined? ? environment_value : nil, environment_name: environment_defined? ? environment_value[:name] : nil, diff --git a/lib/gitlab/ci/config/entry/rules.rb b/lib/gitlab/ci/config/entry/rules.rb index 65cad0880f5..2fbc3d9e367 100644 --- a/lib/gitlab/ci/config/entry/rules.rb +++ b/lib/gitlab/ci/config/entry/rules.rb @@ -26,6 +26,10 @@ module Gitlab end end end + + def value + @config + end end end end diff --git a/lib/gitlab/ci/pipeline/seed/build.rb b/lib/gitlab/ci/pipeline/seed/build.rb index 1066331062b..1f6b3853069 100644 --- a/lib/gitlab/ci/pipeline/seed/build.rb +++ b/lib/gitlab/ci/pipeline/seed/build.rb @@ -145,7 +145,7 @@ module Gitlab def rules_attributes strong_memoize(:rules_attributes) do - @using_rules ? @rules.evaluate(@pipeline, self).to_h.compact : {} + @using_rules ? @rules.evaluate(@pipeline, self).build_attributes : {} end end end diff --git a/lib/gitlab/ci/yaml_processor.rb b/lib/gitlab/ci/yaml_processor.rb index 501d91fa9ad..986605efdc3 100644 --- a/lib/gitlab/ci/yaml_processor.rb +++ b/lib/gitlab/ci/yaml_processor.rb @@ -42,6 +42,7 @@ module Gitlab yaml_variables: yaml_variables(name), needs_attributes: job[:needs]&.map { |need| { name: need } }, interruptible: job[:interruptible], + rules: job[:rules], options: { image: job[:image], services: job[:services], |