jjb: lttng-modules fix ppc build failure on ubuntu
[lttng-ci.git] / scripts / lttng-modules / master-rt.groovy
CommitLineData
f3d8604b
MJ
1/**
2 * Copyright (C) 2016 - Michael Jeanson <mjeanson@efficios.com>
3 *
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.
8 *
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.
13 *
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/>.
16 */
17
18import hudson.model.*
19import hudson.AbortException
20import hudson.console.HyperlinkNote
21import java.util.concurrent.CancellationException
22import org.eclipse.jgit.api.Git
23import org.eclipse.jgit.lib.Ref
24
25
26class kVersion implements Comparable<kVersion> {
27
28 Integer major = 0;
29 Integer majorB = 0;
30 Integer minor = 0;
31 Integer patch = 0;
2c1d386a 32 Integer rt = 0;
f3d8604b
MJ
33
34 kVersion() {}
35
36 kVersion(version) {
37 this.parse(version)
38 }
39
40 def parse(version) {
41 this.major = 0
42 this.majorB = 0
43 this.minor = 0
44 this.patch = 0
2c1d386a 45 this.rt = 0
f3d8604b 46
2c1d386a 47 def match = version =~ /^v(\d+)\.(\d+)(\.(\d+))?(\.(\d+))?(-rt(\d+)-rebase)$/
f3d8604b
MJ
48 if (!match) {
49 throw new Exception("Invalid kernel version: ${version}")
50 }
51
52 Integer offset = 0;
53
54 // Major
55 this.major = Integer.parseInt(match.group(1))
56 if (this.major <= 2) {
57 offset = 2
58 this.majorB = Integer.parseInt(match.group(2))
59 }
60
61 // Minor
62 if (match.group(2 + offset) != null) {
63 this.minor = Integer.parseInt(match.group(2 + offset))
64 }
65
66 // Patch level
67 if (match.group(4 + offset) != null) {
68 this.patch = Integer.parseInt(match.group(4 + offset))
69 }
70
2c1d386a
MJ
71 // RT
72 this.rt = Integer.parseInt(match.group(8))
f3d8604b
MJ
73 }
74
75 @Override int compareTo(kVersion o) {
76 if (this.major != o.major) {
77 return Integer.compare(this.major, o.major);
78 }
79 if (this.majorB != o.majorB) {
80 return Integer.compare(this.majorB, o.majorB);
81 }
82 if (this.minor != o.minor) {
83 return Integer.compare(this.minor, o.minor);
84 }
85 if (this.patch != o.patch) {
86 return Integer.compare(this.patch, o.patch);
87 }
2c1d386a
MJ
88 if (this.rt != o.rc) {
89 return Integer.compare(this.rt, o.rt);
f3d8604b
MJ
90 }
91
92 // Same version
93 return 0;
94 }
95
96 String toString() {
97 String vString = "v${this.major}"
98
99 if (this.majorB > 0) {
100 vString = vString.concat(".${this.majorB}")
101 }
102
103 vString = vString.concat(".${this.minor}")
104
105 if (this.patch > 0) {
106 vString = vString.concat(".${this.patch}")
107 }
108
2c1d386a
MJ
109 if (this.rt > 0) {
110 vString = vString.concat("-rt${this.rt}-rebase")
f3d8604b
MJ
111 }
112 return vString
113 }
114}
115
116
117// Retrieve parameters of the current build
118def mversion = build.buildVariableResolver.resolve('mversion')
119def maxConcurrentBuild = build.buildVariableResolver.resolve('maxConcurrentBuild')
120def kgitrepo = build.buildVariableResolver.resolve('kgitrepo')
121def kverfloor = new kVersion(build.buildVariableResolver.resolve('kverfloor'))
122def job = Hudson.instance.getJob(build.buildVariableResolver.resolve('kbuildjob'))
bcf4d9d0 123def currentJobName = build.project.getFullDisplayName()
f3d8604b
MJ
124
125// Get the out variable
126def config = new HashMap()
127def bindings = getBinding()
128config.putAll(bindings.getVariables())
129def out = config['out']
130
131def jlc = new jenkins.model.JenkinsLocationConfiguration()
132def jenkinsUrl = jlc.url
133
134// Get tags from git repository
135def refs = Git.lsRemoteRepository().setTags(true).setRemote(kgitrepo).call();
136
137// Get kernel versions to build
138def kversions = []
f3d8604b 139for (ref in refs) {
2c1d386a 140 def match = ref.getName() =~ /^refs\/tags\/(v[\d\.]+(-rt(\d+)-rebase))$/
f3d8604b
MJ
141
142 if (match) {
143 def v = new kVersion(match.group(1))
144
145 if (v >= kverfloor) {
2c1d386a 146 kversions.add(v)
f3d8604b
MJ
147 }
148 }
149}
150
151kversions.sort()
f3d8604b
MJ
152
153// Debug
154println "Building the following kernel versions:"
155for (k in kversions) {
156 println k
157}
158
159// Debug: Stop build here
160//throw new InterruptedException()
161
162def joburl = HyperlinkNote.encodeTo('/' + job.url, job.fullDisplayName)
163
164def allBuilds = []
165def ongoingBuild = []
166def failedRuns = []
167def isFailed = false
168
169// Loop while we have kernel versions remaining or jobs running
170while ( kversions.size() != 0 || ongoingBuild.size() != 0 ) {
171
172 if(ongoingBuild.size() < maxConcurrentBuild.toInteger() && kversions.size() != 0) {
173 def kversion = kversions.pop()
174 def job_params = [
175 new StringParameterValue('mversion', mversion),
176 new StringParameterValue('kversion', kversion.toString()),
177 new StringParameterValue('kgitrepo', kgitrepo),
178 ]
179
180 // Launch the parametrized build
181 def param_build = job.scheduleBuild2(0, new Cause.UpstreamCause(build), new ParametersAction(job_params))
182 println "triggering ${joburl} for the ${mversion} branch on kernel ${kversion}"
183
184 // Add it to the ongoing build queue
185 ongoingBuild.push(param_build)
186
187 } else {
188
189 println "Waiting... Queued: " + kversions.size() + " Running: " + ongoingBuild.size()
190 try {
191 Thread.sleep(5000)
192 } catch(e) {
193 if (e in InterruptedException) {
194 build.setResult(hudson.model.Result.ABORTED)
195 throw new InterruptedException()
196 } else {
197 throw(e)
198 }
199 }
200
bcf4d9d0
JR
201 // Check for queued similar job since we only want to run latest
202 // as Mathieu Desnoyers requirement
203 similarJobQueued = Hudson.instance.queue.items.count{it.task.getFullDisplayName() == currentJobName}
204 if ( similarJobQueued > 0 ) {
205 // Abort since new build is queued
206 build.setResult(hudson.model.Result.ABORTED)
207 throw new InterruptedException()
208 }
209
f3d8604b
MJ
210 def i = ongoingBuild.iterator()
211 while ( i.hasNext() ) {
212 currentBuild = i.next()
213 if ( currentBuild.isCancelled() || currentBuild.isDone() ) {
214 // Remove from queue
215 i.remove()
216
217 // Print results
218 def matrixParent = currentBuild.get()
219 allBuilds.add(matrixParent)
220 def kernelStr = matrixParent.buildVariableResolver.resolve("kversion")
221 println "${matrixParent.fullDisplayName} (${kernelStr}) completed with status ${matrixParent.result}"
222
223 // Process child runs of matrixBuild
224 def childRuns = matrixParent.getRuns()
225 for ( childRun in childRuns ) {
226 println "\t${childRun.fullDisplayName} (${kernelStr}) completed with status ${childRun.result}"
227 if (childRun.result != Result.SUCCESS) {
228 failedRuns.add(childRun)
229 isFailed = true
230 }
231 }
232 }
233 }
234 }
235}
236
237// Get log of failed runs
238for (failedRun in failedRuns) {
239 println "---START---"
240 failedRun.writeWholeLogTo(out)
241 println "---END---"
242}
243
244println "---Build report---"
245for (b in allBuilds) {
246 def kernelStr = b.buildVariableResolver.resolve("kversion")
247 println "${b.fullDisplayName} (${kernelStr}) completed with status ${b.result}"
7e02032c 248 // Cleanup builds
7e942863
MJ
249 try {
250 b.delete()
251 } catch (all) {}
f3d8604b
MJ
252}
253
254// Mark this build failed if any child build has failed
255if (isFailed) {
256 build.getExecutor().interrupt(Result.FAILURE)
257}
258
259// EOF
This page took 0.031904 seconds and 4 git commands to generate.