Leonardo Sandoval | 46226da | 2021-01-15 13:55:56 -0600 | [diff] [blame] | 1 | import hudson.model.* |
| 2 | |
| 3 | void log(msg) { |
| 4 | manager.listener.logger.println(msg) |
| 5 | } |
| 6 | |
| 7 | def findRealUrl(url) { |
| 8 | def connection = url.openConnection() |
| 9 | connection.followRedirects = false |
| 10 | connection.requestMethod = "GET" |
| 11 | connection.connect() |
| 12 | if (connection.responseCode == 302) { |
| 13 | if (connection.headerFields.'Location') { |
| 14 | return findRealUrl(connection.headerFields.Location.first().toURL()) |
| 15 | } else { |
| 16 | log('Failed to follow redirect') |
| 17 | } |
| 18 | } |
| 19 | return url |
| 20 | } |
| 21 | |
Leonardo Sandoval | ecbc6f4 | 2021-03-19 10:36:24 -0600 | [diff] [blame] | 22 | def repo_under_test = manager.build.buildVariables.get('REPO_UNDER_TEST') |
| 23 | def artifact = "${repo_under_test}/static-checks.log" |
Leonardo Sandoval | 46226da | 2021-01-15 13:55:56 -0600 | [diff] [blame] | 24 | def jobUrl = manager.hudson.getRootUrl() + "${manager.build.url}artifact/${artifact}" |
| 25 | def url = new URL(jobUrl) |
| 26 | def realUrl = findRealUrl(url) |
| 27 | def connection = realUrl.openConnection() |
| 28 | connection.requestMethod = "GET" |
| 29 | if (connection.responseCode == 200) { |
| 30 | def summaryContent = connection.content.text |
| 31 | def summary = manager.createSummary("clipboard.gif") |
| 32 | def buildResult = manager.build.getResult() |
| 33 | def summaryHeader = "" |
| 34 | if (buildResult == Result.SUCCESS) { |
| 35 | summaryHeader = '<h1 style="color:green;">All good! Here\'s a summary of the static checks warnings (if any):</h1>' |
| 36 | } else { |
| 37 | summaryHeader = '<h1 style="color:red;">Some static checks failed!</h1>' |
| 38 | } |
| 39 | summary.appendText(summaryHeader, false) |
| 40 | summary.appendText("Here's a summary of the static check analysis :", false) |
| 41 | summary.appendText("<pre>" + summaryContent + "</pre>", false) |
| 42 | } else { |
| 43 | log("Connection response code: ${connection.responseCode}") |
| 44 | } |