Class: Tumugi::Plugin::CommandTask

Inherits:
Task
  • Object
show all
Defined in:
lib/tumugi/plugin/task/command.rb

Instance Method Summary collapse

Instance Method Details

#outputObject



17
18
19
20
21
22
23
# File 'lib/tumugi/plugin/task/command.rb', line 17

def output
  unless output_file.nil?
    @output ||= Tumugi::Plugin::LocalFileTarget.new(output_file)
  else
    nil
  end
end

#runObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/tumugi/plugin/task/command.rb', line 25

def run
  log "Execute command: #{command}"
  begin
    out, err, status = Open3.capture3(env, *Shellwords.split(command))
  rescue => e
    raise Tumugi::TumugiError, e.message
  end

  logger.info out unless out.empty?
  logger.error err unless err.empty?

  if status.exitstatus == 0
    if output_file && _output
      log "Save STDOUT into #{output.path}"
      output.open('w') do |f|
        f.print(out)
      end
    end
  else
    raise Tumugi::TumugiError, "Command failed: exit status is #{status.exitstatus}"
  end
end