Last active
January 4, 2016 21:19
-
-
Save ryangreenberg/8679701 to your computer and use it in GitHub Desktop.
Checks with Jenkins until a building job has passed or failed. This script is not well written.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby -KU | |
require 'open-uri' | |
require 'rubygems' | |
require 'json' | |
CHECK_INTERVAL = 5 # seconds | |
NOTIFICATION_CENTER = "/Applications/Utilities/terminal-notifier.app/Contents/MacOS/terminal-notifier" | |
PASS = "SUCCESS" | |
FAIL = "FAILURE" | |
def alert(msg) | |
puts msg | |
system("hash growlnotify && growlnotify -m '#{msg}'") | |
system("#{NOTIFICATION_CENTER} -message '#{msg}'") if File.exist?(NOTIFICATION_CENTER) | |
system("say '#{msg}' &") | |
end | |
build_url = ARGV.first | |
abort("Usage: #{$0} <build_url>") unless build_url && build_url.start_with?("http") | |
build = nil | |
while true | |
json = open("#{build_url.chomp('/')}/api/json").read | |
build = JSON.parse(json) | |
break unless build["building"] | |
sleep CHECK_INTERVAL | |
end | |
if build["result"] == PASS | |
alert("Tests passed for Jenkins build #{build['number']}") | |
exit(0) | |
else | |
alert("say 'Tests failed for Jenkins build #{build['number']}'") | |
exit(1) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment