2 * Copyright (C) 2016 - Michael Jeanson <mjeanson@efficios.com>
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 import hudson.AbortException
20 import hudson.console.HyperlinkNote
21 import java.util.concurrent.CancellationException
22 import org.eclipse.jgit.api.Git
23 import org.eclipse.jgit.lib.Ref
26 // Retrieve parameters of the current build
27 def mversion = build.buildVariableResolver.resolve('mversion')
28 def maxConcurrentBuild = build.buildVariableResolver.resolve('maxConcurrentBuild')
29 def kgitrepo = build.buildVariableResolver.resolve('kgitrepo')
30 def uversion = build.buildVariableResolver.resolve('uversion')
31 def job = Hudson.instance.getJob(build.buildVariableResolver.resolve('kbuildjob'))
33 // Get the out variable
34 def config = new HashMap()
35 def bindings = getBinding()
36 config.putAll(bindings.getVariables())
37 def out = config['out']
39 def jlc = new jenkins.model.JenkinsLocationConfiguration()
40 def jenkinsUrl = jlc.url
42 // Get tags from git repository
43 def refs = Git.lsRemoteRepository().setTags(true).setRemote(kgitrepo).call();
45 // Get kernel versions to build
53 ~/^refs\/tags\/(Ubuntu-4\.4\.0-[\d\.]+)$/,
54 ~/^refs\/tags\/(Ubuntu-lts-.*_16\.04\.\d+)$/,
60 ~/^refs\/tags\/(Ubuntu-3\.13\.0-[\d\.]+)$/,
61 ~/^refs\/tags\/(Ubuntu-lts-.*_14\.04\.\d+)$/,
66 println 'Unsupported Ubuntu version: ${uversion}'
67 throw new InterruptedException()
72 for (matchStr in matchStrs) {
73 def match = ref.getName() =~ matchStr
76 kversions.add(match.group(1))
84 println "Building the following kernel versions:"
85 for (k in kversions) {
89 // Debug: Stop build here
90 //throw new InterruptedException()
92 def joburl = HyperlinkNote.encodeTo('/' + job.url, job.fullDisplayName)
99 // Loop while we have kernel versions remaining or jobs running
100 while ( kversions.size() != 0 || ongoingBuild.size() != 0 ) {
102 if(ongoingBuild.size() < maxConcurrentBuild.toInteger() && kversions.size() != 0) {
103 def kversion = kversions.pop()
105 new StringParameterValue('mversion', mversion),
106 new StringParameterValue('kversion', kversion),
107 new StringParameterValue('kgitrepo', kgitrepo),
110 // Launch the parametrized build
111 def param_build = job.scheduleBuild2(0, new Cause.UpstreamCause(build), new ParametersAction(job_params))
112 println "triggering ${joburl} for the ${mversion} branch on kernel ${kversion}"
114 // Add it to the ongoing build queue
115 ongoingBuild.push(param_build)
119 println "Waiting... Queued: " + kversions.size() + " Running: " + ongoingBuild.size()
123 if (e in InterruptedException) {
124 build.setResult(hudson.model.Result.ABORTED)
125 throw new InterruptedException()
131 def i = ongoingBuild.iterator()
132 while ( i.hasNext() ) {
133 currentBuild = i.next()
134 if ( currentBuild.isCancelled() || currentBuild.isDone() ) {
139 def matrixParent = currentBuild.get()
140 allBuilds.add(matrixParent)
141 def kernelStr = matrixParent.buildVariableResolver.resolve("kversion")
142 println "${matrixParent.fullDisplayName} (${kernelStr}) completed with status ${matrixParent.result}"
144 // Process child runs of matrixBuild
145 def childRuns = matrixParent.getRuns()
146 for ( childRun in childRuns ) {
147 println "\t${childRun.fullDisplayName} (${kernelStr}) completed with status ${childRun.result}"
148 if (childRun.result != Result.SUCCESS) {
149 failedRuns.add(childRun)
158 // Get log of failed runs
159 for (failedRun in failedRuns) {
160 println "---START---"
161 failedRun.writeWholeLogTo(out)
165 println "---Build report---"
166 for (b in allBuilds) {
167 def kernelStr = b.buildVariableResolver.resolve("kversion")
168 println "${b.fullDisplayName} (${kernelStr}) completed with status ${b.result}"
172 // TODO: Delete only builds generated from this job run
173 for (b in job.getBuilds()) {
177 // Mark this build failed if any child build has failed
179 build.getExecutor().interrupt(Result.FAILURE)