Module: Kite::Helpers::Concourse
- Defined in:
- lib/kite/helpers/concourse.rb
Overview
Helpers for concourse scripts
Class Method Summary collapse
- .execute(command, env = {}, gsub_log_args = nil) ⇒ Object
- .fatal(message) ⇒ Object
- .log(msg) ⇒ Object
- .params(data) ⇒ Object
- .respond(data) ⇒ Object
Class Method Details
.execute(command, env = {}, gsub_log_args = nil) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/kite/helpers/concourse.rb', line 27 def self.execute(command, env = {}, gsub_log_args = nil) command_log = gsub_log_args ? command.gsub(*gsub_log_args) : command log("+ #{ command_log }") Open3.popen2e(env, command) do |stdin, stdout, wait_thr| ::Kite::Helpers::Concourse.log(stdout.read) return wait_thr.value.exitstatus.zero? end end |
.fatal(message) ⇒ Object
22 23 24 25 |
# File 'lib/kite/helpers/concourse.rb', line 22 def self.fatal() respond(version: { status: 'error' }, metadata: []) exit 1 end |
.log(msg) ⇒ Object
12 13 14 |
# File 'lib/kite/helpers/concourse.rb', line 12 def self.log(msg) msg.split("\n").each { |line| $stderr.puts("[LOG] --- #{line}") } end |
.params(data) ⇒ Object
8 9 10 |
# File 'lib/kite/helpers/concourse.rb', line 8 def self.params(data) JSON.parse data end |
.respond(data) ⇒ Object
16 17 18 19 20 |
# File 'lib/kite/helpers/concourse.rb', line 16 def self.respond(data) # keep only valid concourse values data.select! { |k, _| k.to_s =~ /(version|metadata)/ } puts JSON.dump(data) end |