Add lttng-modules bionic jobs
[lttng-ci.git] / scripts / lttng-modules / master.groovy
CommitLineData
f3d8604b 1/**
e9b44189 2 * Copyright (C) 2016-2017 - Michael Jeanson <mjeanson@efficios.com>
f3d8604b
MJ
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
3a01c580
MJ
26class InvalidKVersionException extends Exception {
27 public InvalidKVersionException(String message) {
591756e5
MJ
28 super(message)
29 }
30}
31
3a01c580
MJ
32class EmptyKVersionException extends Exception {
33 public EmptyKVersionException(String message) {
591756e5
MJ
34 super(message)
35 }
36}
37
3a01c580 38class VanillaKVersion implements Comparable<VanillaKVersion> {
f3d8604b 39
3a01c580
MJ
40 Integer major = 0
41 Integer majorB = 0
42 Integer minor = 0
43 Integer patch = 0
44 Integer rc = Integer.MAX_VALUE
f3d8604b 45
3a01c580 46 VanillaKVersion() {}
f3d8604b 47
3a01c580 48 VanillaKVersion(version) {
f3d8604b
MJ
49 this.parse(version)
50 }
51
3a01c580
MJ
52 static VanillaKVersion minKVersion() {
53 return new VanillaKVersion("v0.0.0")
54 }
55
56 static VanillaKVersion maxKVersion() {
57 return new VanillaKVersion("v" + Integer.MAX_VALUE + ".0.0")
58 }
59
60 static VanillaKVersion factory(version) {
61 return new VanillaKVersion(version)
62 }
63
f3d8604b
MJ
64 def parse(version) {
65 this.major = 0
66 this.majorB = 0
67 this.minor = 0
68 this.patch = 0
69 this.rc = Integer.MAX_VALUE
70
591756e5 71 if (!version) {
3a01c580 72 throw new EmptyKVersionException("Empty kernel version")
591756e5
MJ
73 }
74
f3d8604b
MJ
75 def match = version =~ /^v(\d+)\.(\d+)(\.(\d+))?(\.(\d+))?(-rc(\d+))?$/
76 if (!match) {
3a01c580 77 throw new InvalidKVersionException("Invalid kernel version: ${version}")
f3d8604b
MJ
78 }
79
80 Integer offset = 0;
81
82 // Major
83 this.major = Integer.parseInt(match.group(1))
84 if (this.major <= 2) {
85 offset = 2
86 this.majorB = Integer.parseInt(match.group(2))
87 }
88
89 // Minor
90 if (match.group(2 + offset) != null) {
91 this.minor = Integer.parseInt(match.group(2 + offset))
92 }
93
94 // Patch level
95 if (match.group(4 + offset) != null) {
96 this.patch = Integer.parseInt(match.group(4 + offset))
97 }
98
99 // RC
100 if (match.group(8) != null) {
101 this.rc = Integer.parseInt(match.group(8))
102 }
103 }
104
105 // Return true if this version is a release candidate
106 Boolean isRC() {
107 return this.rc != Integer.MAX_VALUE
108 }
109
e9b44189 110 // Return true if both version are of the same stable branch
3a01c580 111 Boolean isSameStable(VanillaKVersion o) {
e9b44189
MJ
112 if (this.major != o.major) {
113 return false
114 }
115 if (this.majorB != o.majorB) {
116 return false
117 }
118 if (this.minor != o.minor) {
119 return false
120 }
121
122 return true
123 }
124
3a01c580 125 @Override int compareTo(VanillaKVersion o) {
f3d8604b 126 if (this.major != o.major) {
e9b44189 127 return Integer.compare(this.major, o.major)
f3d8604b
MJ
128 }
129 if (this.majorB != o.majorB) {
e9b44189 130 return Integer.compare(this.majorB, o.majorB)
f3d8604b
MJ
131 }
132 if (this.minor != o.minor) {
e9b44189 133 return Integer.compare(this.minor, o.minor)
f3d8604b
MJ
134 }
135 if (this.patch != o.patch) {
e9b44189 136 return Integer.compare(this.patch, o.patch)
f3d8604b
MJ
137 }
138 if (this.rc != o.rc) {
e9b44189 139 return Integer.compare(this.rc, o.rc)
f3d8604b
MJ
140 }
141
142 // Same version
143 return 0;
144 }
145
146 String toString() {
147 String vString = "v${this.major}"
148
149 if (this.majorB > 0) {
150 vString = vString.concat(".${this.majorB}")
151 }
152
153 vString = vString.concat(".${this.minor}")
154
155 if (this.patch > 0) {
156 vString = vString.concat(".${this.patch}")
157 }
158
159 if (this.rc > 0 && this.rc < Integer.MAX_VALUE) {
160 vString = vString.concat("-rc${this.rc}")
161 }
162 return vString
163 }
164}
165
3a01c580
MJ
166class UbuntuKVersion implements Comparable<UbuntuKVersion> {
167
168 Integer major = 0
169 Integer minor = 0
170 Integer patch = 0
171 Integer umajor = 0
172 Integer uminor = 0
173 String suffix = ""
174 Boolean isLTS = false
175
176 UbuntuKVersion() {}
177
178 UbuntuKVersion(version) {
179 this.parse(version)
180 }
181
182 static UbuntuKVersion minKVersion() {
183 return new UbuntuKVersion("Ubuntu-lts-0.0.0-0.0")
184 }
185
186 static UbuntuKVersion maxKVersion() {
187 return new UbuntuKVersion("Ubuntu-" + Integer.MAX_VALUE + ".0.0-0.0")
188 }
189
190 static UbuntuKVersion factory(version) {
191 return new UbuntuKVersion(version)
192 }
193
194 def parse(version) {
195 this.major = 0
196 this.minor = 0
197 this.patch = 0
198 this.umajor = 0
199 this.uminor = 0
200 this.suffix = "";
201 this.isLTS = false
202
203 if (!version) {
204 throw new EmptyKVersionException("Empty kernel version")
205 }
206
207 //'Ubuntu-lts-4.8.0-27.29_16.04.1',
208 //'Ubuntu-4.4.0-70.91',
209 def match = version =~ /^Ubuntu-(lts-)??(\d+)\.(\d+)\.(\d+)-(\d+)\.(\d+)(.*)??$/
210 if (!match) {
211 throw new InvalidKVersionException("Invalid kernel version: ${version}")
212 }
213
214 this.isLTS = match.group(1) != null
215
216 // Major
217 this.major = Integer.parseInt(match.group(2))
218
219 // Minor
220 this.minor = Integer.parseInt(match.group(3))
221
222 // Patch level
223 this.patch = Integer.parseInt(match.group(4))
224
225 // Ubuntu major
226 this.umajor = Integer.parseInt(match.group(5))
227
228 // Ubuntu minor
229 this.uminor = Integer.parseInt(match.group(6))
230
231 if (match.group(7) != null) {
232 this.suffix = match.group(7)
233 }
234 }
235
236 // Return true if this version is a release candidate
237 Boolean isRC() {
238 return false
239 }
240
241 // Return true if both version are of the same stable branch
242 Boolean isSameStable(UbuntuKVersion o) {
243 if (this.isLTS != o.isLTS) {
244 return false
245 }
246 if (this.major != o.major) {
247 return false
248 }
249 if (this.minor != o.minor) {
250 return false
251 }
252 if (this.patch != o.patch) {
253 return false
254 }
255
256 return true
257 }
258
259 @Override int compareTo(UbuntuKVersion o) {
260 if (this.major != o.major) {
261 return Integer.compare(this.major, o.major)
262 }
263 if (this.minor != o.minor) {
264 return Integer.compare(this.minor, o.minor)
265 }
266 if (this.patch != o.patch) {
267 return Integer.compare(this.patch, o.patch)
268 }
269 if (this.umajor != o.umajor) {
270 return Integer.compare(this.umajor, o.umajor)
271 }
272 if (this.uminor != o.uminor) {
273 return Integer.compare(this.uminor, o.uminor)
274 }
275 if (this.isLTS != o.isLTS) {
276 if (o.isLTS) {
277 return 1
278 } else {
279 return -1
280 }
281 }
282
283 // Same version
284 return 0;
285 }
286
287 String toString() {
288 String vString = "Ubuntu-"
289
290 if (this.isLTS) {
291 vString = vString.concat("lts-")
292 }
293
294 vString = vString.concat("${this.major}.${this.minor}.${this.patch}-${this.umajor}.${this.uminor}${this.suffix}")
295
296 return vString
297 }
298}
299
f3d8604b
MJ
300
301// Retrieve parameters of the current build
302def mversion = build.buildVariableResolver.resolve('mversion')
303def maxConcurrentBuild = build.buildVariableResolver.resolve('maxConcurrentBuild')
304def kgitrepo = build.buildVariableResolver.resolve('kgitrepo')
591756e5
MJ
305def kverfloor_raw = build.buildVariableResolver.resolve('kverfloor')
306def kverceil_raw = build.buildVariableResolver.resolve('kverceil')
e9b44189 307def kverfilter = build.buildVariableResolver.resolve('kverfilter')
3a01c580 308def uversion = build.buildVariableResolver.resolve('uversion')
f3d8604b 309def job = Hudson.instance.getJob(build.buildVariableResolver.resolve('kbuildjob'))
483859f3 310def currentJobName = build.project.getFullDisplayName()
f3d8604b 311
591756e5 312
f3d8604b
MJ
313// Get the out variable
314def config = new HashMap()
315def bindings = getBinding()
316config.putAll(bindings.getVariables())
317def out = config['out']
318
f3d8604b
MJ
319
320// Get tags from git repository
321def refs = Git.lsRemoteRepository().setTags(true).setRemote(kgitrepo).call();
322
323// Get kernel versions to build
324def kversions = []
325def kversionsRC = []
3a01c580
MJ
326def matchStrs = []
327def blacklist = []
328def kversionFactory = ""
329
330if (uversion != null) {
331 kversionFactory = new UbuntuKVersion()
332 switch (uversion) {
57bdee9e
MJ
333 case 'bionic':
334 matchStrs = [
335 ~/^refs\/tags\/(Ubuntu-4\.15\.0-\d{1,3}?\.[\d]+)$/,
336 ]
337 break
338
3a01c580
MJ
339 case 'xenial':
340 matchStrs = [
341 ~/^refs\/tags\/(Ubuntu-4\.4\.0-\d{1,3}?\.[\d]+)$/,
342 ~/^refs\/tags\/(Ubuntu-lts-4\.8\.0-.*_16\.04\.\d+)$/,
343 ~/^refs\/tags\/(Ubuntu-lts-4\.10\.0-.*_16\.04\.\d+)$/,
57bdee9e 344 ~/^refs\/tags\/(Ubuntu-lts-4\.15\.0-.*_16\.04\.\d+)$/,
3a01c580
MJ
345 ]
346
347 blacklist = [
348 'Ubuntu-lts-4.10.0-7.9_16.04.1',
349 ]
350 break
351
352 case 'trusty':
353 matchStrs = [
354 ~/^refs\/tags\/(Ubuntu-3\.13\.0-[\d\.]+)$/,
355 ~/^refs\/tags\/(Ubuntu-lts-.*_14\.04\.\d+)$/,
356 ]
357 break
358
359 default:
57bdee9e 360 println "Unsupported Ubuntu version: ${uversion}"
3a01c580
MJ
361 throw new InterruptedException()
362 break
363 }
364} else {
365 // Vanilla
366 kversionFactory = new VanillaKVersion()
367 matchStrs = [
368 ~/^refs\/tags\/(v[\d\.]+(-rc(\d+))?)$/,
369 ]
370}
f3d8604b 371
3a01c580
MJ
372// Parse kernel versions
373def kverfloor = ""
374try {
375 kverfloor = kversionFactory.factory(kverfloor_raw)
376} catch (EmptyKVersionException e) {
377 kverfloor = kversionFactory.minKVersion()
378}
f3d8604b 379
3a01c580
MJ
380def kverceil = ""
381try {
382 kverceil = kversionFactory.factory(kverceil_raw)
383} catch (EmptyKVersionException e) {
384 kverceil = kversionFactory.maxKVersion()
385}
386
387// Build a sorted list of versions to build
388for (ref in refs) {
389 for (matchStr in matchStrs) {
390 def match = ref.getName() =~ matchStr
391 if (match && !blacklist.contains(match.group(1))) {
392 def v = kversionFactory.factory(match.group(1))
393
394 if ((v >= kverfloor) && (v < kverceil)) {
395 if (v.isRC()) {
396 kversionsRC.add(v)
397 } else {
398 kversions.add(v)
399 }
f3d8604b
MJ
400 }
401 }
402 }
403}
404
405kversions.sort()
406kversionsRC.sort()
407
e9b44189
MJ
408switch (kverfilter) {
409 case 'stable-head':
410 // Keep only the head of each stable branch
411 println('Filter kernel versions to keep only the latest point release of each stable branch.')
412
413 for (i = 0; i < kversions.size(); i++) {
414 def curr = kversions[i]
415 def next = i < kversions.size() - 1 ? kversions[i + 1] : null
416
417 if (next != null) {
418 if (curr.isSameStable(next)) {
419 kversions.remove(i)
420 i--
421 }
422 }
423 }
424 break
425
426 default:
427 // No filtering of kernel versions
428 println('No kernel versions filtering selected.')
429 break
430}
431
f3d8604b 432// If the last RC version is newer than the last stable, add it to the build list
3a01c580 433if (kversionsRC.size() > 0 && kversionsRC.last() > kversions.last()) {
f3d8604b
MJ
434 kversions.add(kversionsRC.last())
435}
436
f3d8604b
MJ
437println "Building the following kernel versions:"
438for (k in kversions) {
439 println k
440}
441
442// Debug: Stop build here
443//throw new InterruptedException()
444
445def joburl = HyperlinkNote.encodeTo('/' + job.url, job.fullDisplayName)
446
447def allBuilds = []
448def ongoingBuild = []
449def failedRuns = []
450def isFailed = false
483859f3 451def similarJobQueued = 0;
f3d8604b
MJ
452
453// Loop while we have kernel versions remaining or jobs running
454while ( kversions.size() != 0 || ongoingBuild.size() != 0 ) {
455
456 if(ongoingBuild.size() < maxConcurrentBuild.toInteger() && kversions.size() != 0) {
457 def kversion = kversions.pop()
458 def job_params = [
459 new StringParameterValue('mversion', mversion),
a1ae361e 460 new StringParameterValue('ktag', kversion.toString()),
f3d8604b
MJ
461 new StringParameterValue('kgitrepo', kgitrepo),
462 ]
463
464 // Launch the parametrized build
465 def param_build = job.scheduleBuild2(0, new Cause.UpstreamCause(build), new ParametersAction(job_params))
466 println "triggering ${joburl} for the ${mversion} branch on kernel ${kversion}"
467
468 // Add it to the ongoing build queue
469 ongoingBuild.push(param_build)
470
471 } else {
472
473 println "Waiting... Queued: " + kversions.size() + " Running: " + ongoingBuild.size()
474 try {
3a01c580 475 Thread.sleep(10000)
f3d8604b
MJ
476 } catch(e) {
477 if (e in InterruptedException) {
478 build.setResult(hudson.model.Result.ABORTED)
479 throw new InterruptedException()
480 } else {
481 throw(e)
482 }
483 }
484
3a01c580 485 // Abort job if a newer instance is queued
483859f3
JR
486 similarJobQueued = Hudson.instance.queue.items.count{it.task.getFullDisplayName() == currentJobName}
487 if ( similarJobQueued > 0 ) {
483859f3
JR
488 build.setResult(hudson.model.Result.ABORTED)
489 throw new InterruptedException()
490 }
491
f3d8604b
MJ
492 def i = ongoingBuild.iterator()
493 while ( i.hasNext() ) {
494 currentBuild = i.next()
495 if ( currentBuild.isCancelled() || currentBuild.isDone() ) {
496 // Remove from queue
497 i.remove()
498
499 // Print results
500 def matrixParent = currentBuild.get()
501 allBuilds.add(matrixParent)
a1ae361e 502 def kernelStr = matrixParent.buildVariableResolver.resolve("ktag")
f3d8604b
MJ
503 println "${matrixParent.fullDisplayName} (${kernelStr}) completed with status ${matrixParent.result}"
504
505 // Process child runs of matrixBuild
506 def childRuns = matrixParent.getRuns()
507 for ( childRun in childRuns ) {
508 println "\t${childRun.fullDisplayName} (${kernelStr}) completed with status ${childRun.result}"
509 if (childRun.result != Result.SUCCESS) {
510 failedRuns.add(childRun)
511 isFailed = true
512 }
513 }
514 }
515 }
516 }
517}
518
519// Get log of failed runs
520for (failedRun in failedRuns) {
521 println "---START---"
522 failedRun.writeWholeLogTo(out)
523 println "---END---"
524}
525
526println "---Build report---"
527for (b in allBuilds) {
a1ae361e 528 def kernelStr = b.buildVariableResolver.resolve("ktag")
f3d8604b 529 println "${b.fullDisplayName} (${kernelStr}) completed with status ${b.result}"
7e02032c 530 // Cleanup builds
7e942863
MJ
531 try {
532 b.delete()
533 } catch (all) {}
f3d8604b
MJ
534}
535
536// Mark this build failed if any child build has failed
537if (isFailed) {
c5c05f73 538 build.setResult(hudson.model.Result.FAILURE)
f3d8604b
MJ
539}
540
541// EOF
This page took 0.046903 seconds and 4 git commands to generate.