blob: 2515d09a09c66b034aee573a45d1fe6c672f65d4 [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')
18 def testDescription = "&nbsp;Test Job Id: <a href='${testJobUrl}'>${testJobId}</a>"
19
20 def causes = manager.build.getAction(hudson.model.CauseAction.class).getCauses()
21 if (causes[0] instanceof hudson.model.Cause.UpstreamCause) {
22 def rootCause = getUpstreamRoot(causes[0])
23 def upstreamBuild = rootCause.upstreamBuild
24 def upstreamProject = rootCause.upstreamProject
25 def jobName = upstreamProject
26 def jobConfiguration = upstreamProject
27 def jobUrl = manager.hudson.getRootUrl() + "job/${upstreamProject}/${upstreamBuild}"
28 def jobDescription = "<br>&nbsp;Build <a href='${jobUrl}'>${upstreamProject} #${upstreamBuild}</a>"
29
30 manager.build.setDescription(testDescription + jobDescription)
31 def upstreamBuildInstance = hudson.model.Hudson.instance.getItem(jobName).getBuildByNumber(upstreamBuild)
32 upstreamBuildDescription = upstreamBuildInstance.getDescription()
33 if (null == upstreamBuildDescription) {
34 upstreamBuildDescription = "";
35 }
36 upstreamBuildDescription = upstreamBuildDescription + testDescription
37 upstreamBuildInstance.setDescription(upstreamBuildDescription)
38 }
39}