blob: d17c8e6437edacbb9ff33003b812439fb02ed0ef [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
Paul Sokolovsky5aba7332023-03-16 18:18:05 +070017def matcher = manager.getLogMatcher("LAVA URL: (?<url>.*?) LAVA JOB ID: (?<jobid>\\d+)")
Milosz Wasilewski10438582020-12-03 11:36:21 +000018if (matcher?.matches()) {
19 def testJobId = matcher.group('jobid')
20 def testJobUrl = matcher.group('url')
Paul Sokolovskyc5189372023-12-30 14:17:11 +030021 description += "LAVA Job Id: <a href='${testJobUrl}'>${testJobId}</a>\n"
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 Sokolovsky117c7c52024-01-04 12:20:18 +030024 description += " | <a href='${lavaLogUrl}'>log</a>\n"
Leonardo Sandovala8078d62021-02-11 16:29:25 -060025
Paul Sokolovsky2e533b42024-01-09 21:50:20 +030026 // Verify LAVA jobs results, all tests must pass, otherwise turn build into FAILED
Leonardo Sandovala8078d62021-02-11 16:29:25 -060027 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 Sokolovsky2e533b42024-01-09 21:50:20 +030032 manager.buildFailure()
Leonardo Sandovala8078d62021-02-11 16:29:25 -060033 }
34 }
Milosz Wasilewski10438582020-12-03 11:36:21 +000035}
Paul Sokolovsky7c1186b2021-11-09 17:16:55 +030036
Paul Sokolovsky63414352023-12-30 12:12:35 +030037// Add a TuxSuite job link to the description
38matcher = manager.getLogMatcher("TuxSuite test ID: (?<tuxid>[A-Za-z0-9]+)")
39if (matcher?.matches()) {
40 def tuxId = matcher.group('tuxid')
41 def abbrTuxId = "..." + tuxId.substring(19)
Arthur She78acaae2025-02-05 06:15:04 +010042
43 // Retrieve environment variables
44 def tuxsuiteGroup = System.getenv('TUXSUITE_GROUP')
45 def tuxsuiteProject = System.getenv('TUXSUITE_PROJECT')
46
47 // Exit with an error if either variable is not set
48 if (!tuxsuiteGroup || !tuxsuiteProject) {
49 manager.buildFailure()
50 throw new RuntimeException("Error: TUXSUITE_GROUP or TUXSUITE_PROJECT environment variable is not set.")
51 }
52
53 description += "Tux Id: <a href='https://tuxapi.tuxsuite.com/v1/groups/${tuxsuiteGroup}/projects/${tuxsuiteProject}/tests/${tuxId}'>${abbrTuxId}</a>\n"
54 description += " | <a href='https://storage.tuxsuite.com/public/${tuxsuiteGroup}/${tuxsuiteProject}/tests/${tuxId}/lava-logs.html'>log</a>\n"
Paul Sokolovskyff615d92024-01-26 16:29:55 +070055
56 // Verify test job results set build status as FAILED if needed
57 def testMatcher = manager.getLogMatcher("TuxSuite test result: (?<result>\\d+)")
58 if (testMatcher?.matches()) {
59 def testJobSuiteResult = testMatcher.group('result')
60 // result = 1 means job fails
61 if (testJobSuiteResult == "1") {
62 manager.buildFailure()
63 }
64 }
Paul Sokolovsky63414352023-12-30 12:12:35 +030065}
66
67
Paul Sokolovsky7c1186b2021-11-09 17:16:55 +030068def causes = manager.build.getAction(hudson.model.CauseAction.class).getCauses()
69if (causes[0] instanceof hudson.model.Cause.UpstreamCause) {
70 def rootCause = getUpstreamRoot(causes[0])
71 def upstreamBuild = rootCause.upstreamBuild
72 def upstreamProject = rootCause.upstreamProject
73 def jobName = upstreamProject
74 def jobConfiguration = upstreamProject
75 def jobUrl = "${rootUrl}job/${upstreamProject}/${upstreamBuild}"
Paul Sokolovskyc5189372023-12-30 14:17:11 +030076 description += "<br>Top build: <a href='${jobUrl}'>${upstreamProject} #${upstreamBuild}</a>"
Paul Sokolovsky7c1186b2021-11-09 17:16:55 +030077}
78
79// Set accumulated description
80manager.build.setDescription(description)