2020-03-13 15:44:24 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
module Ci
|
|
|
|
class Config
|
|
|
|
module Entry
|
|
|
|
##
|
|
|
|
# Entry that represents a CI/CD Bridge job that is responsible for
|
|
|
|
# defining a downstream project trigger.
|
|
|
|
#
|
|
|
|
class Bridge < ::Gitlab::Config::Entry::Node
|
2020-04-08 14:13:33 +05:30
|
|
|
include ::Gitlab::Ci::Config::Entry::Processable
|
2020-03-13 15:44:24 +05:30
|
|
|
|
2021-01-03 14:25:43 +05:30
|
|
|
ALLOWED_WHEN = %w[on_success on_failure always manual].freeze
|
2021-04-17 20:07:23 +05:30
|
|
|
ALLOWED_KEYS = %i[trigger parallel].freeze
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
validations do
|
2020-04-08 14:13:33 +05:30
|
|
|
validates :config, allowed_keys: ALLOWED_KEYS + PROCESSABLE_ALLOWED_KEYS
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
with_options allow_nil: true do
|
2023-01-13 00:05:48 +05:30
|
|
|
validates :when, type: String, inclusion: {
|
2021-01-03 14:25:43 +05:30
|
|
|
in: ALLOWED_WHEN,
|
|
|
|
message: "should be one of: #{ALLOWED_WHEN.join(', ')}"
|
|
|
|
}
|
2021-02-22 17:27:13 +05:30
|
|
|
validates :allow_failure, boolean: true
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
validate on: :composed do
|
2020-04-08 14:13:33 +05:30
|
|
|
unless trigger_defined? || bridge_needs.present?
|
2020-03-13 15:44:24 +05:30
|
|
|
errors.add(:config, 'should contain either a trigger or a needs:pipeline')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
validate on: :composed do
|
|
|
|
next unless bridge_needs.present?
|
|
|
|
next if bridge_needs.one?
|
|
|
|
|
|
|
|
errors.add(:config, 'should contain at most one bridge need')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
entry :trigger, ::Gitlab::Ci::Config::Entry::Trigger,
|
|
|
|
description: 'CI/CD Bridge downstream trigger definition.',
|
|
|
|
inherit: false
|
|
|
|
|
|
|
|
entry :needs, ::Gitlab::Ci::Config::Entry::Needs,
|
|
|
|
description: 'CI/CD Bridge needs dependency definition.',
|
|
|
|
inherit: false,
|
|
|
|
metadata: { allowed_needs: %i[job bridge] }
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
entry :parallel, Entry::Product::Parallel,
|
|
|
|
description: 'Parallel configuration for this job.',
|
|
|
|
inherit: false,
|
|
|
|
metadata: { allowed_strategies: %i(matrix) }
|
|
|
|
|
|
|
|
attributes :when, :allow_failure, :parallel
|
2020-03-13 15:44:24 +05:30
|
|
|
|
|
|
|
def self.matching?(name, config)
|
|
|
|
!name.to_s.start_with?('.') &&
|
|
|
|
config.is_a?(Hash) &&
|
|
|
|
(config.key?(:trigger) || config.key?(:needs))
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.visible?
|
|
|
|
true
|
|
|
|
end
|
|
|
|
|
|
|
|
def value
|
2020-04-08 14:13:33 +05:30
|
|
|
super.merge(
|
2020-03-13 15:44:24 +05:30
|
|
|
trigger: (trigger_value if trigger_defined?),
|
|
|
|
needs: (needs_value if needs_defined?),
|
2021-01-03 14:25:43 +05:30
|
|
|
ignore: ignored?,
|
2020-04-08 14:13:33 +05:30
|
|
|
when: self.when,
|
2021-04-17 20:07:23 +05:30
|
|
|
scheduling_type: needs_defined? && !bridge_needs ? :dag : :stage,
|
|
|
|
parallel: has_parallel? ? parallel_value : nil
|
2020-04-08 14:13:33 +05:30
|
|
|
).compact
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def bridge_needs
|
|
|
|
needs_value[:bridge] if needs_value
|
|
|
|
end
|
2021-02-22 17:27:13 +05:30
|
|
|
|
|
|
|
def ignored?
|
|
|
|
allow_failure.nil? ? manual_action? : allow_failure
|
|
|
|
end
|
2020-03-13 15:44:24 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|