Milosz Wasilewski | 1043858 | 2020-12-03 11:36:21 +0000 | [diff] [blame] | 1 | import hudson.model.* |
| 2 | |
| 3 | def getUpstreamRoot(cause) { |
| 4 | causes = cause.getUpstreamCauses() |
| 5 | if (causes.size() > 0) { |
| 6 | if (causes[0] instanceof hudson.model.Cause.UpstreamCause) { |
| 7 | return getUpstreamRoot(causes[0]) |
| 8 | } |
| 9 | } |
| 10 | return cause |
| 11 | } |
| 12 | |
Paul Sokolovsky | 7c1186b | 2021-11-09 17:16:55 +0300 | [diff] [blame] | 13 | def description = "" |
| 14 | def rootUrl = manager.hudson.getRootUrl() |
| 15 | |
Milosz Wasilewski | 1043858 | 2020-12-03 11:36:21 +0000 | [diff] [blame] | 16 | // Add a LAVA job link to the description |
Paul Sokolovsky | 5aba733 | 2023-03-16 18:18:05 +0700 | [diff] [blame] | 17 | def matcher = manager.getLogMatcher("LAVA URL: (?<url>.*?) LAVA JOB ID: (?<jobid>\\d+)") |
Milosz Wasilewski | 1043858 | 2020-12-03 11:36:21 +0000 | [diff] [blame] | 18 | if (matcher?.matches()) { |
| 19 | def testJobId = matcher.group('jobid') |
| 20 | def testJobUrl = matcher.group('url') |
Paul Sokolovsky | c518937 | 2023-12-30 14:17:11 +0300 | [diff] [blame] | 21 | description += "LAVA Job Id: <a href='${testJobUrl}'>${testJobId}</a>\n" |
Leonardo Sandoval | 9f15980 | 2021-01-20 16:47:25 -0600 | [diff] [blame] | 22 | |
Leonardo Sandoval | 9f15980 | 2021-01-20 16:47:25 -0600 | [diff] [blame] | 23 | def lavaLogUrl = "${rootUrl}${manager.build.url}artifact/lava.log" |
Paul Sokolovsky | 117c7c5 | 2024-01-04 12:20:18 +0300 | [diff] [blame] | 24 | description += " | <a href='${lavaLogUrl}'>log</a>\n" |
Leonardo Sandoval | a8078d6 | 2021-02-11 16:29:25 -0600 | [diff] [blame] | 25 | |
Paul Sokolovsky | 2e533b4 | 2024-01-09 21:50:20 +0300 | [diff] [blame^] | 26 | // Verify LAVA jobs results, all tests must pass, otherwise turn build into FAILED |
Leonardo Sandoval | a8078d6 | 2021-02-11 16:29:25 -0600 | [diff] [blame] | 27 | def testMatcher = manager.getLogMatcher("LAVA JOB RESULT: (?<result>\\d+)") |
| 28 | if (testMatcher?.matches()) { |
| 29 | def testJobSuiteResult = testMatcher.group('result') |
| 30 | // result = 1 means lava job fails |
| 31 | if (testJobSuiteResult == "1") { |
Paul Sokolovsky | 2e533b4 | 2024-01-09 21:50:20 +0300 | [diff] [blame^] | 32 | manager.buildFailure() |
Leonardo Sandoval | a8078d6 | 2021-02-11 16:29:25 -0600 | [diff] [blame] | 33 | } |
| 34 | } |
Milosz Wasilewski | 1043858 | 2020-12-03 11:36:21 +0000 | [diff] [blame] | 35 | } |
Paul Sokolovsky | 7c1186b | 2021-11-09 17:16:55 +0300 | [diff] [blame] | 36 | |
Paul Sokolovsky | 6341435 | 2023-12-30 12:12:35 +0300 | [diff] [blame] | 37 | // Add a TuxSuite job link to the description |
| 38 | matcher = manager.getLogMatcher("TuxSuite test ID: (?<tuxid>[A-Za-z0-9]+)") |
| 39 | if (matcher?.matches()) { |
| 40 | def tuxId = matcher.group('tuxid') |
| 41 | def abbrTuxId = "..." + tuxId.substring(19) |
| 42 | description += "Tux Id: <a href='https://tuxapi.tuxsuite.com/v1/groups/tfc/projects/ci/tests/${tuxId}'>${abbrTuxId}</a>\n" |
Paul Sokolovsky | fb8bb83 | 2024-01-06 00:02:39 +0300 | [diff] [blame] | 43 | description += " | <a href='https://storage.tuxsuite.com/public/tfc/ci/tests/${tuxId}/lava-logs.html'>log</a>\n" |
Paul Sokolovsky | 6341435 | 2023-12-30 12:12:35 +0300 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | |
Paul Sokolovsky | 7c1186b | 2021-11-09 17:16:55 +0300 | [diff] [blame] | 47 | def causes = manager.build.getAction(hudson.model.CauseAction.class).getCauses() |
| 48 | if (causes[0] instanceof hudson.model.Cause.UpstreamCause) { |
| 49 | def rootCause = getUpstreamRoot(causes[0]) |
| 50 | def upstreamBuild = rootCause.upstreamBuild |
| 51 | def upstreamProject = rootCause.upstreamProject |
| 52 | def jobName = upstreamProject |
| 53 | def jobConfiguration = upstreamProject |
| 54 | def jobUrl = "${rootUrl}job/${upstreamProject}/${upstreamBuild}" |
Paul Sokolovsky | c518937 | 2023-12-30 14:17:11 +0300 | [diff] [blame] | 55 | description += "<br>Top build: <a href='${jobUrl}'>${upstreamProject} #${upstreamBuild}</a>" |
Paul Sokolovsky | 7c1186b | 2021-11-09 17:16:55 +0300 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | // Set accumulated description |
| 59 | manager.build.setDescription(description) |