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 | |
| 13 | // Add a LAVA job link to the description |
| 14 | def matcher = manager.getLogMatcher("TEST JOB URL: (?<url>.*?) TEST JOB ID: (?<jobid>\\d+)") |
| 15 | if (matcher?.matches()) { |
| 16 | def testJobId = matcher.group('jobid') |
| 17 | def testJobUrl = matcher.group('url') |
Fathi Boudra | db7baca | 2021-01-26 21:38:17 +0100 | [diff] [blame] | 18 | def testDescription = " Test Job Id: <a href='${testJobUrl}'>${testJobId}</a>" |
Leonardo Sandoval | 9f15980 | 2021-01-20 16:47:25 -0600 | [diff] [blame] | 19 | |
| 20 | def rootUrl = manager.hudson.getRootUrl() |
| 21 | def lavaLogUrl = "${rootUrl}${manager.build.url}artifact/lava.log" |
| 22 | def lavaDescription = "<br > LAVA log: <a href='${lavaLogUrl}'>lava.log</a>" |
Milosz Wasilewski | 1043858 | 2020-12-03 11:36:21 +0000 | [diff] [blame] | 23 | |
| 24 | def causes = manager.build.getAction(hudson.model.CauseAction.class).getCauses() |
| 25 | if (causes[0] instanceof hudson.model.Cause.UpstreamCause) { |
| 26 | def rootCause = getUpstreamRoot(causes[0]) |
| 27 | def upstreamBuild = rootCause.upstreamBuild |
| 28 | def upstreamProject = rootCause.upstreamProject |
| 29 | def jobName = upstreamProject |
| 30 | def jobConfiguration = upstreamProject |
Leonardo Sandoval | 9f15980 | 2021-01-20 16:47:25 -0600 | [diff] [blame] | 31 | def jobUrl = "${rootUrl}job/${upstreamProject}/${upstreamBuild}" |
Milosz Wasilewski | 1043858 | 2020-12-03 11:36:21 +0000 | [diff] [blame] | 32 | def jobDescription = "<br> Build <a href='${jobUrl}'>${upstreamProject} #${upstreamBuild}</a>" |
| 33 | |
Leonardo Sandoval | 9f15980 | 2021-01-20 16:47:25 -0600 | [diff] [blame] | 34 | manager.build.setDescription(testDescription + lavaDescription + jobDescription) |
Milosz Wasilewski | 1043858 | 2020-12-03 11:36:21 +0000 | [diff] [blame] | 35 | } |
Leonardo Sandoval | a8078d6 | 2021-02-11 16:29:25 -0600 | [diff] [blame^] | 36 | |
| 37 | // Verify LAVA jobs results, all tests must pass, otherwise turn build into UNSTABLE |
| 38 | def testMatcher = manager.getLogMatcher("LAVA JOB RESULT: (?<result>\\d+)") |
| 39 | if (testMatcher?.matches()) { |
| 40 | def testJobSuiteResult = testMatcher.group('result') |
| 41 | // result = 1 means lava job fails |
| 42 | if (testJobSuiteResult == "1") { |
| 43 | manager.buildFailure() |
| 44 | } |
| 45 | } |
Milosz Wasilewski | 1043858 | 2020-12-03 11:36:21 +0000 | [diff] [blame] | 46 | } |