blob: 1737e1b413d5656706176a009681cbc5dbb74255 [file] [log] [blame]
Milosz Wasilewski10438582020-12-03 11:36:21 +00001import hudson.model.*
2
3def 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
14def matcher = manager.getLogMatcher("TEST JOB URL: (?<url>.*?) TEST JOB ID: (?<jobid>\\d+)")
15if (matcher?.matches()) {
16 def testJobId = matcher.group('jobid')
17 def testJobUrl = matcher.group('url')
Fathi Boudradb7baca2021-01-26 21:38:17 +010018 def testDescription = "&nbsp;Test Job Id: <a href='${testJobUrl}'>${testJobId}</a>"
Leonardo Sandoval9f159802021-01-20 16:47:25 -060019
20 def rootUrl = manager.hudson.getRootUrl()
21 def lavaLogUrl = "${rootUrl}${manager.build.url}artifact/lava.log"
22 def lavaDescription = "<br >&nbsp;LAVA log: <a href='${lavaLogUrl}'>lava.log</a>"
Milosz Wasilewski10438582020-12-03 11:36:21 +000023
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 Sandoval9f159802021-01-20 16:47:25 -060031 def jobUrl = "${rootUrl}job/${upstreamProject}/${upstreamBuild}"
Milosz Wasilewski10438582020-12-03 11:36:21 +000032 def jobDescription = "<br>&nbsp;Build <a href='${jobUrl}'>${upstreamProject} #${upstreamBuild}</a>"
33
Leonardo Sandoval9f159802021-01-20 16:47:25 -060034 manager.build.setDescription(testDescription + lavaDescription + jobDescription)
Milosz Wasilewski10438582020-12-03 11:36:21 +000035 }
Leonardo Sandovala8078d62021-02-11 16:29:25 -060036
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 Wasilewski10438582020-12-03 11:36:21 +000046}