2016-07-05 08:04:22 -04:00
|
|
|
module Gitlab
|
|
|
|
module Ci
|
|
|
|
class Config
|
2016-11-14 04:31:45 -05:00
|
|
|
module Entry
|
2016-07-05 08:04:22 -04:00
|
|
|
##
|
|
|
|
# Entry that represents a concrete CI/CD job.
|
|
|
|
#
|
2016-11-14 04:31:45 -05:00
|
|
|
class Job < Node
|
2016-07-05 08:04:22 -04:00
|
|
|
include Configurable
|
2016-07-18 10:33:20 -04:00
|
|
|
include Attributable
|
|
|
|
|
2016-07-20 04:59:49 -04:00
|
|
|
ALLOWED_KEYS = %i[tags script only except type image services allow_failure
|
|
|
|
type stage when artifacts cache dependencies before_script
|
2017-02-21 18:32:18 -05:00
|
|
|
after_script variables environment coverage].freeze
|
2016-07-20 04:59:49 -04:00
|
|
|
|
2016-07-09 12:43:26 -04:00
|
|
|
validations do
|
2016-07-20 04:59:49 -04:00
|
|
|
validates :config, allowed_keys: ALLOWED_KEYS
|
2016-07-09 12:43:26 -04:00
|
|
|
validates :config, presence: true
|
2016-11-18 08:14:41 -05:00
|
|
|
validates :script, presence: true
|
2016-07-15 15:07:51 -04:00
|
|
|
validates :name, presence: true
|
|
|
|
validates :name, type: Symbol
|
2016-07-18 10:33:20 -04:00
|
|
|
|
|
|
|
with_options allow_nil: true do
|
|
|
|
validates :tags, array_of_strings: true
|
|
|
|
validates :allow_failure, boolean: true
|
2016-07-19 07:08:28 -04:00
|
|
|
validates :when,
|
2016-07-20 04:44:01 -04:00
|
|
|
inclusion: { in: %w[on_success on_failure always manual],
|
|
|
|
message: 'should be on_success, on_failure, ' \
|
|
|
|
'always or manual' }
|
2016-07-20 08:15:18 -04:00
|
|
|
|
|
|
|
validates :dependencies, array_of_strings: true
|
2016-07-18 10:33:20 -04:00
|
|
|
end
|
2016-07-09 12:43:26 -04:00
|
|
|
end
|
|
|
|
|
2016-11-14 04:51:56 -05:00
|
|
|
entry :before_script, Entry::Script,
|
2016-07-10 07:54:39 -04:00
|
|
|
description: 'Global before script overridden in this job.'
|
|
|
|
|
2016-11-14 04:51:56 -05:00
|
|
|
entry :script, Entry::Commands,
|
2016-07-10 08:35:53 -04:00
|
|
|
description: 'Commands that will be executed in this job.'
|
|
|
|
|
2016-11-14 04:51:56 -05:00
|
|
|
entry :stage, Entry::Stage,
|
2016-07-09 08:56:41 -04:00
|
|
|
description: 'Pipeline stage this job will be executed into.'
|
|
|
|
|
2016-11-14 04:51:56 -05:00
|
|
|
entry :type, Entry::Stage,
|
2016-07-09 08:56:41 -04:00
|
|
|
description: 'Deprecated: stage this job will be executed into.'
|
|
|
|
|
2016-11-14 04:51:56 -05:00
|
|
|
entry :after_script, Entry::Script,
|
2016-07-10 08:41:14 -04:00
|
|
|
description: 'Commands that will be executed when finishing job.'
|
|
|
|
|
2016-11-14 04:51:56 -05:00
|
|
|
entry :cache, Entry::Cache,
|
2016-07-14 10:01:18 -04:00
|
|
|
description: 'Cache definition for this job.'
|
|
|
|
|
2016-11-14 04:51:56 -05:00
|
|
|
entry :image, Entry::Image,
|
2016-07-18 03:54:38 -04:00
|
|
|
description: 'Image that will be used to execute this job.'
|
|
|
|
|
2016-11-14 04:51:56 -05:00
|
|
|
entry :services, Entry::Services,
|
2016-07-18 03:54:38 -04:00
|
|
|
description: 'Services that will be used to execute this job.'
|
|
|
|
|
2016-11-14 04:51:56 -05:00
|
|
|
entry :only, Entry::Trigger,
|
2016-07-18 06:37:42 -04:00
|
|
|
description: 'Refs policy this job will be executed for.'
|
|
|
|
|
2016-11-14 04:51:56 -05:00
|
|
|
entry :except, Entry::Trigger,
|
2016-07-18 06:37:42 -04:00
|
|
|
description: 'Refs policy this job will be executed for.'
|
|
|
|
|
2016-11-14 04:51:56 -05:00
|
|
|
entry :variables, Entry::Variables,
|
2016-07-18 07:09:00 -04:00
|
|
|
description: 'Environment variables available for this job.'
|
|
|
|
|
2016-11-14 04:51:56 -05:00
|
|
|
entry :artifacts, Entry::Artifacts,
|
2016-07-18 08:15:01 -04:00
|
|
|
description: 'Artifacts configuration for this job.'
|
|
|
|
|
2016-11-14 04:51:56 -05:00
|
|
|
entry :environment, Entry::Environment,
|
2016-09-14 13:52:28 -04:00
|
|
|
description: 'Environment configuration for this job.'
|
|
|
|
|
2016-11-17 22:42:35 -05:00
|
|
|
entry :coverage, Entry::Coverage,
|
2016-11-19 19:48:02 -05:00
|
|
|
description: 'Coverage configuration for this job.'
|
2016-11-13 22:56:39 -05:00
|
|
|
|
2016-07-18 03:54:38 -04:00
|
|
|
helpers :before_script, :script, :stage, :type, :after_script,
|
2016-07-18 08:15:01 -04:00
|
|
|
:cache, :image, :services, :only, :except, :variables,
|
2016-11-17 22:42:35 -05:00
|
|
|
:artifacts, :commands, :environment, :coverage
|
2016-07-09 08:56:41 -04:00
|
|
|
|
2016-11-18 08:14:41 -05:00
|
|
|
attributes :script, :tags, :allow_failure, :when, :dependencies
|
|
|
|
|
2016-08-25 07:58:46 -04:00
|
|
|
def compose!(deps = nil)
|
2016-08-25 07:49:15 -04:00
|
|
|
super do
|
|
|
|
if type_defined? && !stage_defined?
|
|
|
|
@entries[:stage] = @entries[:type]
|
|
|
|
end
|
|
|
|
|
|
|
|
@entries.delete(:type)
|
|
|
|
end
|
2016-08-29 06:44:14 -04:00
|
|
|
|
|
|
|
inherit!(deps)
|
2016-08-25 07:49:15 -04:00
|
|
|
end
|
|
|
|
|
2016-07-14 07:14:09 -04:00
|
|
|
def name
|
2016-07-15 15:07:51 -04:00
|
|
|
@metadata[:name]
|
2016-07-14 07:14:09 -04:00
|
|
|
end
|
|
|
|
|
2016-07-09 08:56:41 -04:00
|
|
|
def value
|
2016-07-10 07:54:39 -04:00
|
|
|
@config.merge(to_hash.compact)
|
2016-07-09 08:56:41 -04:00
|
|
|
end
|
|
|
|
|
2016-08-29 07:11:35 -04:00
|
|
|
def commands
|
|
|
|
(before_script_value.to_a + script_value.to_a).join("\n")
|
|
|
|
end
|
|
|
|
|
2017-03-06 06:01:33 -05:00
|
|
|
def manual_action?
|
|
|
|
self.when == 'manual'
|
|
|
|
end
|
|
|
|
|
|
|
|
def ignored?
|
|
|
|
allow_failure.nil? ? manual_action? : allow_failure
|
|
|
|
end
|
|
|
|
|
2016-07-09 08:56:41 -04:00
|
|
|
private
|
|
|
|
|
2016-08-29 06:44:14 -04:00
|
|
|
def inherit!(deps)
|
|
|
|
return unless deps
|
|
|
|
|
|
|
|
self.class.nodes.each_key do |key|
|
|
|
|
global_entry = deps[key]
|
2016-11-22 03:09:38 -05:00
|
|
|
job_entry = self[key]
|
2016-08-29 06:44:14 -04:00
|
|
|
|
|
|
|
if global_entry.specified? && !job_entry.specified?
|
|
|
|
@entries[key] = global_entry
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-07-10 07:54:39 -04:00
|
|
|
def to_hash
|
2016-07-15 15:07:51 -04:00
|
|
|
{ name: name,
|
2016-11-18 08:14:41 -05:00
|
|
|
before_script: before_script_value,
|
|
|
|
script: script_value,
|
2016-08-29 07:11:35 -04:00
|
|
|
commands: commands,
|
2016-11-18 08:14:41 -05:00
|
|
|
image: image_value,
|
|
|
|
services: services_value,
|
|
|
|
stage: stage_value,
|
|
|
|
cache: cache_value,
|
|
|
|
only: only_value,
|
|
|
|
except: except_value,
|
|
|
|
variables: variables_defined? ? variables_value : nil,
|
|
|
|
environment: environment_defined? ? environment_value : nil,
|
|
|
|
environment_name: environment_defined? ? environment_value[:name] : nil,
|
2016-11-17 22:42:35 -05:00
|
|
|
coverage: coverage_defined? ? coverage_value : nil,
|
2016-11-18 08:14:41 -05:00
|
|
|
artifacts: artifacts_value,
|
2017-03-06 06:01:33 -05:00
|
|
|
after_script: after_script_value,
|
|
|
|
ignore: ignored? }
|
2016-07-10 07:54:39 -04:00
|
|
|
end
|
2016-07-05 08:04:22 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|