65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
# File 'lib/jester/cli.rb', line 65
def build
if File.file?(@options[:pipeline_file])
pipeline = File.read(@options[:pipeline_file])
else
puts "File not found: " + @options[:pipeline_file]
raise 'FileNotFound'
end
job_params = {
description: @options[:job_name],
script: pipeline }
xml = pipeline_xml(job_params)
if job_exists?(@options[:job_name])
path = "/job/" + @options[:job_name] + "/config.xml"
puts "Job already exists, using path: #{path}" if debug
else
path = "/createItem?name=" + @options[:job_name]
puts "Job doesn't exist yet, using path: #{path}" if debug
end
begin
r = post( @options[:url] + path, xml )
if r.status != 200
puts "Job config update failed."
raise 'JobPostFailed'
else
puts "Job config update succeeded."
end
rescue Exception => e
puts "Exception: " + e.message
puts "POST response status: #{r.status}"
puts "POST response body: #{r.body}" if debug
return e
end
build_path = "/job/" + @options[:job_name] + "/build?delay=0sec"
build_resp = post( @options[:url] + build_path )
if build_resp.status != 201
puts "Unable to run build. Quit"
quit
else
puts "Build running - getting output..."
end
resp = get(@options[:url] + "/job/" + @options[:job_name] + "/api/json")
json = JSON.parse(resp.body)
if json['inQueue'] == false
build_num = json['lastBuild']['number']
end
build = build_result(@options[:job_name], build_num)
puts "Job " + build_num.to_s + " result: " + build['result']
log = log_result(@options[:job_name], build_num)
puts "DEBUG: " + log.body if debug
File.write("#{@options[:job_name]}.log", log.body)
puts "See #{@options[:job_name]}.log for output."
end
|