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 |
| 17 | def matcher = manager.getLogMatcher("TEST JOB URL: (?<url>.*?) TEST JOB ID: (?<jobid>\\d+)") |
| 18 | if (matcher?.matches()) { |
| 19 | def testJobId = matcher.group('jobid') |
| 20 | def testJobUrl = matcher.group('url') |
Paul Sokolovsky | 7c1186b | 2021-11-09 17:16:55 +0300 | [diff] [blame^] | 21 | description += " Test Job Id: <a href='${testJobUrl}'>${testJobId}</a>" |
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 | 7c1186b | 2021-11-09 17:16:55 +0300 | [diff] [blame^] | 24 | description += "<br > LAVA log: <a href='${lavaLogUrl}'>lava.log</a>" |
Leonardo Sandoval | a8078d6 | 2021-02-11 16:29:25 -0600 | [diff] [blame] | 25 | |
| 26 | // Verify LAVA jobs results, all tests must pass, otherwise turn build into UNSTABLE |
| 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") { |
| 32 | manager.buildFailure() |
| 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 | |
| 37 | def causes = manager.build.getAction(hudson.model.CauseAction.class).getCauses() |
| 38 | if (causes[0] instanceof hudson.model.Cause.UpstreamCause) { |
| 39 | def rootCause = getUpstreamRoot(causes[0]) |
| 40 | def upstreamBuild = rootCause.upstreamBuild |
| 41 | def upstreamProject = rootCause.upstreamProject |
| 42 | def jobName = upstreamProject |
| 43 | def jobConfiguration = upstreamProject |
| 44 | def jobUrl = "${rootUrl}job/${upstreamProject}/${upstreamBuild}" |
| 45 | description += "<br> Build <a href='${jobUrl}'>${upstreamProject} #${upstreamBuild}</a>" |
| 46 | } |
| 47 | |
| 48 | // Set accumulated description |
| 49 | manager.build.setDescription(description) |