2018-10-26 04:12:43 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-03-02 16:44:15 +00:00
|
|
|
module Gitlab
|
|
|
|
module Ci
|
|
|
|
module Build
|
|
|
|
class Step
|
2019-08-31 19:25:25 +00:00
|
|
|
WHEN_ON_FAILURE = 'on_failure'
|
|
|
|
WHEN_ON_SUCCESS = 'on_success'
|
|
|
|
WHEN_ALWAYS = 'always'
|
2017-03-02 16:44:15 +00:00
|
|
|
|
2017-03-07 11:30:34 +00:00
|
|
|
attr_reader :name
|
2017-03-23 13:37:49 +00:00
|
|
|
attr_accessor :script, :timeout, :when, :allow_failure
|
2017-03-02 16:44:15 +00:00
|
|
|
|
|
|
|
class << self
|
|
|
|
def from_commands(job)
|
|
|
|
self.new(:script).tap do |step|
|
2017-07-06 14:57:34 +00:00
|
|
|
step.script = job.options[:before_script].to_a + job.options[:script].to_a
|
2018-03-26 17:26:52 +00:00
|
|
|
step.timeout = job.metadata_timeout
|
2017-03-02 16:44:15 +00:00
|
|
|
step.when = WHEN_ON_SUCCESS
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-06-16 18:09:01 +00:00
|
|
|
def from_release(job)
|
|
|
|
release = job.options[:release]
|
|
|
|
return unless release
|
|
|
|
|
|
|
|
self.new(:release).tap do |step|
|
|
|
|
step.script = Gitlab::Ci::Build::Releaser.new(config: job.options[:release]).script
|
|
|
|
step.timeout = job.metadata_timeout
|
|
|
|
step.when = WHEN_ON_SUCCESS
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-03-02 16:44:15 +00:00
|
|
|
def from_after_script(job)
|
|
|
|
after_script = job.options[:after_script]
|
|
|
|
return unless after_script
|
|
|
|
|
|
|
|
self.new(:after_script).tap do |step|
|
|
|
|
step.script = after_script
|
2018-03-26 17:26:52 +00:00
|
|
|
step.timeout = job.metadata_timeout
|
2017-03-02 16:44:15 +00:00
|
|
|
step.when = WHEN_ALWAYS
|
2017-03-07 11:30:34 +00:00
|
|
|
step.allow_failure = true
|
2017-03-02 16:44:15 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(name)
|
|
|
|
@name = name
|
|
|
|
@allow_failure = false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|