blob: 7cdaa88207ade6e5a007faf71d2acf09cec6e536 [file] [log] [blame]
import hudson.model.*
void log(msg) {
manager.listener.logger.println(msg)
}
def findRealUrl(url) {
def connection = url.openConnection()
connection.followRedirects = false
connection.requestMethod = "GET"
connection.connect()
if (connection.responseCode == 302) {
if (connection.headerFields.'Location') {
return findRealUrl(connection.headerFields.Location.first().toURL())
} else {
log('Failed to follow redirect')
}
}
return url
}
def repo_under_test = manager.build.buildVariables.get('REPO_UNDER_TEST')
def artifact = "${repo_under_test}/static-checks.log"
def jobUrl = manager.hudson.getRootUrl() + "${manager.build.url}artifact/${artifact}"
def url = new URL(jobUrl)
def realUrl = findRealUrl(url)
def connection = realUrl.openConnection()
connection.requestMethod = "GET"
if (connection.responseCode == 200) {
def summaryContent = connection.content.text
def summary = manager.createSummary("clipboard.gif")
def buildResult = manager.build.getResult()
def summaryHeader = ""
if (buildResult == Result.SUCCESS) {
summaryHeader = '<h1 style="color:green;">All good! Here\'s a summary of the static checks warnings (if any):</h1>'
} else {
summaryHeader = '<h1 style="color:red;">Some static checks failed!</h1>'
}
summary.appendText(summaryHeader, false)
summary.appendText("Here's a summary of the static check analysis :", false)
summary.appendText("<pre>" + summaryContent + "</pre>", false)
} else {
log("Connection response code: ${connection.responseCode}")
}