blob: 65c1898f1c4fb4bf2bd66617408857931632abbc [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
Paul Sokolovsky7c1186b2021-11-09 17:16:55 +030013def description = ""
14def rootUrl = manager.hudson.getRootUrl()
15
Milosz Wasilewski10438582020-12-03 11:36:21 +000016// Add a LAVA job link to the description
17def matcher = manager.getLogMatcher("TEST JOB URL: (?<url>.*?) TEST JOB ID: (?<jobid>\\d+)")
18if (matcher?.matches()) {
19 def testJobId = matcher.group('jobid')
20 def testJobUrl = matcher.group('url')
Paul Sokolovsky7c1186b2021-11-09 17:16:55 +030021 description += "&nbsp;Test Job Id: <a href='${testJobUrl}'>${testJobId}</a>"
Leonardo Sandoval9f159802021-01-20 16:47:25 -060022
Leonardo Sandoval9f159802021-01-20 16:47:25 -060023 def lavaLogUrl = "${rootUrl}${manager.build.url}artifact/lava.log"
Paul Sokolovsky7c1186b2021-11-09 17:16:55 +030024 description += "<br >&nbsp;LAVA log: <a href='${lavaLogUrl}'>lava.log</a>"
Leonardo Sandovala8078d62021-02-11 16:29:25 -060025
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 Wasilewski10438582020-12-03 11:36:21 +000035}
Paul Sokolovsky7c1186b2021-11-09 17:16:55 +030036
37def causes = manager.build.getAction(hudson.model.CauseAction.class).getCauses()
38if (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>&nbsp;Build <a href='${jobUrl}'>${upstreamProject} #${upstreamBuild}</a>"
46}
47
48// Set accumulated description
49manager.build.setDescription(description)