Fathi Boudra | 8aa4bd8 | 2021-01-15 10:30:57 +0100 | [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 | |
| 22 | if (manager.logContains("Files coverage: [0-9]+%\$")) { |
| 23 | if (!manager.logContains("Files coverage: 100%\$")) { |
| 24 | manager.addShortText("WARNING") |
| 25 | manager.addWarningBadge("Coverage < 100%! See the end of the console output.") |
| 26 | manager.buildUnstable() |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | def artifact = "trusted-firmware-a/tf_coverage.log" |
| 31 | def jobUrl = manager.hudson.getRootUrl() + "${manager.build.url}artifact/${artifact}" |
| 32 | def url = new URL(jobUrl) |
| 33 | def realUrl = findRealUrl(url) |
| 34 | def connection = realUrl.openConnection() |
| 35 | connection.requestMethod = "GET" |
| 36 | if (connection.responseCode == 200) { |
| 37 | def summaryContent = connection.content.text |
| 38 | def summary = manager.createSummary("clipboard.gif") |
| 39 | def buildResult = manager.build.getResult() |
| 40 | def summaryHeader = "" |
| 41 | if (buildResult == Result.SUCCESS) { |
| 42 | summaryHeader = '<h1 style="color:green">Analysis complete. Go to <a href="https://scan.coverity.com/projects/arm-software-arm-trusted-firmware">Coverity Scan Online</a> to see the defects.</h1>' |
| 43 | } else { |
| 44 | summaryHeader = '<h1 style="color:red">Warning: Some files have not been analyzed!</h1>' |
| 45 | } |
| 46 | summary.appendText(summaryHeader, false) |
| 47 | summary.appendText("Here's a summary of the analysis coverage:", false) |
| 48 | summary.appendText("<pre>" + summaryContent + "</pre>", false) |
| 49 | } else { |
| 50 | log("Connection response code: ${connection.responseCode}") |
| 51 | } |