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') |
| 18 | def testDescription = " 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> 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 | } |