Class: Seijaku::Step
- Inherits:
-
Object
- Object
- Seijaku::Step
- Defined in:
- lib/seijaku/step.rb
Overview
A step is a bash or sh command that must be executed. steps execution is always fifo.
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#pipeline ⇒ Object
readonly
Returns the value of attribute pipeline.
Instance Method Summary collapse
- #execute! ⇒ Object
-
#initialize(step, variables, pipeline, logger, task, ssh_hosts = nil, ssh_settings = {}) ⇒ Step
constructor
A new instance of Step.
- #logger_output(result) ⇒ Object
Constructor Details
#initialize(step, variables, pipeline, logger, task, ssh_hosts = nil, ssh_settings = {}) ⇒ Step
Returns a new instance of Step.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/seijaku/step.rb', line 9 def initialize(step, variables, pipeline, logger, task, ssh_hosts = nil, ssh_settings = {}) @sh = step.fetch(:sh, nil) @bash = step.fetch(:bash, nil) @ssh = step.fetch(:ssh, nil) @soft_fail = step.fetch(:soft_fail, false) @output = step.fetch(:output, false) @variables = variables @pipeline = pipeline @logger = logger @task = task @ssh_hosts = ssh_hosts @ssh_settings = ssh_settings @command = (@sh || @bash) || @ssh end |
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command.
7 8 9 |
# File 'lib/seijaku/step.rb', line 7 def command @command end |
#pipeline ⇒ Object (readonly)
Returns the value of attribute pipeline.
7 8 9 |
# File 'lib/seijaku/step.rb', line 7 def pipeline @pipeline end |
Instance Method Details
#execute! ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/seijaku/step.rb', line 25 def execute! result = SHExecutor.new(@sh, @variables).run! if @sh result = BashExecutor.new(@bash, @variables).run! if @bash result = SSHExecutor.new(@ssh, @variables, @task, @ssh_hosts, @ssh_settings).run! if result[:exit_status] != 0 logger_output(result) exit(1) unless @soft_fail end return unless @output %i[stdout stderr].each do |stream| puts format("%<stream>s:\t %<result>s", stream: stream, result: result[stream]) end end |
#logger_output(result) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/seijaku/step.rb', line 42 def logger_output(result) @logger.info <<~OUTPUT command: `#{result[:command]}` exit_code: #{result[:exit_status]} stdout: #{result[:stdout]} stderr: #{result[:stderr]}" OUTPUT end |