Created
December 17, 2013 13:50
-
-
Save willis7/8005197 to your computer and use it in GitHub Desktop.
A simple script for collecting the latest Jenkins build information, parsing it and writing it to the console in HTML format. Requires commons-codec-1.8.jar and commons-httpclient-3.1.jar on the classpath.
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
import org.apache.commons.httpclient.* | |
import org.apache.commons.httpclient.auth.* | |
import org.apache.commons.httpclient.methods.* | |
import groovy.xml.MarkupBuilder | |
def server = "localhost" | |
def port = 8093 | |
def jenkinsHost = "https://${server}:${port}" | |
def username = "yourUsername" | |
def apiToken = "yourPassword" | |
def client = new HttpClient() | |
client.state.setCredentials( | |
new AuthScope( server, port, "realm"), | |
new UsernamePasswordCredentials( username, apiToken ) | |
) | |
// Jenkins does not do any authentication negotiation, | |
// ie. it does not return a 401 (Unauthorized) | |
// but immediately a 403 (Forbidden) | |
client.params.authenticationPreemptive = true | |
def post = new PostMethod( "${jenkinsHost}/rssLatest" ) | |
post.doAuthentication = true | |
File file = new File("rssLatest.xml") | |
try { | |
int result = client.executeMethod(post) | |
file.write(post.getResponseBodyAsString()) | |
} finally { | |
post.releaseConnection() | |
} | |
def builds = new XmlParser().parse("rssLatest.xml") | |
def writer = new StringWriter() | |
def html = new MarkupBuilder(writer) | |
def cssClass | |
def hrefURL | |
html.html { | |
head { | |
title 'Continuous Integration HUD' | |
style(type: 'text/css', """ | |
.stable { background-color: green } | |
.unstable { background-color: yellow } | |
.broken { background-color: red } | |
table { margin: 0 auto; } | |
a { font-size: bigger; text-decoration: none; color: black; }""" | |
) | |
script (src: "http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js") | |
script (type: "text/javascript", """ | |
\\\$(document).ready(redraw); | |
\\\$(window).resize(redraw); | |
function redraw() { | |
\\\$('tr').height((\\\$(window).height()-60)/\\\$('tr').size()); | |
\\\$('td').width((\\\$(window).width()-60)/\\\$('tr').first().find('td').size()); | |
} | |
""" | |
) | |
} | |
body{ | |
table { | |
tr { | |
def counter = 0 | |
builds.each{ item-> | |
cssClass = (item.title.text() =~ 'unstable') ? 'unstable' : 'stable' | |
cssClass = (item.title.text() =~ 'broken') ? 'broken' : cssClass | |
item.link.each{ a -> | |
hrefURL = a.attribute("href") | |
} | |
td(class: cssClass){ | |
a(href: hrefURL, item.title.text()) | |
} | |
counter++ | |
if(counter == 6){ | |
tr{} | |
counter = 0 | |
} | |
} | |
} | |
} | |
} | |
} | |
println writer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment