ansible: Install prometheus metrics plugin on Jenkins servers
[lttng-ci.git] / scripts / lttng-modules / master.groovy
1 /**
2 * Copyright (C) 2016-2020 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
18 import hudson.model.*
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
24
25
26 class InvalidKVersionException extends Exception {
27 public InvalidKVersionException(String message) {
28 super(message)
29 }
30 }
31
32 class EmptyKVersionException extends Exception {
33 public EmptyKVersionException(String message) {
34 super(message)
35 }
36 }
37
38 class VanillaKVersion implements Comparable<VanillaKVersion> {
39
40 Integer major = 0
41 Integer majorB = 0
42 Integer minor = 0
43 Integer patch = 0
44 Integer rc = Integer.MAX_VALUE
45
46 VanillaKVersion() {}
47
48 VanillaKVersion(version) {
49 this.parse(version)
50 }
51
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
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
71 if (!version) {
72 throw new EmptyKVersionException("Empty kernel version")
73 }
74
75 def match = version =~ /^v(\d+)\.(\d+)(\.(\d+))?(\.(\d+))?(-rc(\d+))?$/
76 if (!match) {
77 throw new InvalidKVersionException("Invalid kernel version: ${version}")
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
110 // Return true if both version are of the same stable branch
111 Boolean isSameStable(VanillaKVersion o) {
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
125 @Override int compareTo(VanillaKVersion o) {
126 if (this.major != o.major) {
127 return Integer.compare(this.major, o.major)
128 }
129 if (this.majorB != o.majorB) {
130 return Integer.compare(this.majorB, o.majorB)
131 }
132 if (this.minor != o.minor) {
133 return Integer.compare(this.minor, o.minor)
134 }
135 if (this.patch != o.patch) {
136 return Integer.compare(this.patch, o.patch)
137 }
138 if (this.rc != o.rc) {
139 return Integer.compare(this.rc, o.rc)
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
166 class ElKVersion implements Comparable<ElKVersion> {
167 Integer major = 0
168 Integer minor = 0
169 Integer patch = 0
170 Integer elmajor = 0
171 Integer elminor = 0
172 Integer elpatch = 0
173 Integer el_release_major = 0
174 Integer el_release_minor = 0
175 Boolean append_zero_el_release_minor = false
176 String version_prefix = ""
177
178 ElKVersion() {}
179
180 ElKVersion(version) {
181 this.parse(version)
182 }
183
184 static ElKVersion minKVersion() {
185 return new ElKVersion("kernel-0.0.0-0.0.0.el0_0")
186 }
187
188 static ElKVersion maxKVersion() {
189 return new ElKVersion("kernel-" + Integer.MAX_VALUE + ".0.0-0.0.0.el0_0")
190 }
191
192 static ElKVersion factory(version) {
193 return new ElKVersion(version)
194 }
195
196 def parse(version) {
197 this.major = 0
198 this.minor = 0
199 this.patch = 0
200 this.elmajor = 0
201 this.elminor = 0
202 this.elpatch = 0
203 this.el_release_major = 0
204 this.el_release_minor = 0
205 this.append_zero_el_release_minor = false
206 this.version_prefix = ""
207
208 if (!version) {
209 throw new EmptyKVersionException("Empty kernel version")
210 }
211
212 // Eg. imports/r8/kernel-4.18.0-513.18.1.el8_9
213 // Eg. imports/r9/kernel-5.14.0-362.13.1.el9_3
214 // Eg. imports/r8s/kernel-4.18.0-528.el8
215 // Eg. imports/r8/kernel-4.18.0-80.1.2.el8_0
216 // Eg. imports/r8/kernel-4.18.0-348.el8
217 def match = version =~ /^([\w\d\/]*kernel-)??(\d+)\.(\d+)\.(\d+)-(\d+)(\.(\d+))??(\.(\d+))??\.el(\d+)(_(\d+))??$/
218 if (!match) {
219 throw new InvalidKVersionException("Invalid kernel version: ${version}")
220 }
221
222 if (match.group(1)) {
223 this.version_prefix = match.group(1)
224 }
225 this.major = Integer.parseInt(match.group(2))
226 this.minor = Integer.parseInt(match.group(3))
227 this.patch = Integer.parseInt(match.group(4))
228 this.elmajor = Integer.parseInt(match.group(5))
229 if (match.group(7)) {
230 this.elminor = Integer.parseInt(match.group(7))
231 }
232 if (match.group(9)) {
233 this.elpatch = Integer.parseInt(match.group(9))
234 }
235 if (match.group(10)) {
236 this.el_release_major = Integer.parseInt(match.group(10))
237 }
238 if (match.group(12)) {
239 this.el_release_minor = Integer.parseInt(match.group(12))
240 this.append_zero_el_release_minor = true
241 }
242 }
243
244 Boolean isRC() {
245 return false
246 }
247
248 Boolean isSameStable(ElKVersion o) {
249 def properties = ['major', 'minor', 'patch', 'elmajor', 'elminor', 'elpatch', 'el_release_major', 'el_release_minor']
250 for (property in properties) {
251 if (this."$property" != o."$property") {
252 return false
253 }
254 }
255 return true
256 }
257
258 @Override int compareTo(ElKVersion o) {
259 def properties = ['major', 'minor', 'patch', 'elmajor', 'elminor', 'elpatch', 'el_release_major', 'el_release_minor']
260 for (property in properties) {
261 if (this."$property" != o."$property") {
262 return Integer.compare(this."$property", o."$property")
263 }
264 }
265 return 0
266 }
267
268 String toString() {
269 String vString = "${this.version_prefix}${this.major}.${this.minor}.${this.patch}-${this.elmajor}"
270 // Sometimes a tag can have no elminor, eg. imports/r8/kernel-4.18.0-80.el8
271 if (this.elminor != 0) {
272 vString = vString.concat(".${this.elminor}")
273 }
274 if (this.elpatch != 0) {
275 vString = vString.concat(".${this.elpatch}")
276 }
277 vString = vString.concat(".el${this.el_release_major}")
278 // Some tags have a trailing el_release_minor that is 0, eg.
279 // imports/r8/kernel-4.18.0-80.1.2.el8
280 if (this.el_release_minor != 0 || (this.el_release_minor == 0 && this.append_zero_el_release_minor)) {
281 vString = vString.concat("_${this.el_release_minor}")
282 }
283 return vString
284 }
285 }
286
287 class SlesKVersion implements Comparable<SlesKVersion> {
288 Integer major = 0
289 Integer minor = 0
290 Integer patch = 0
291 Integer slesrelease = 0
292 Integer slesmajor = 0
293 Integer slesminor = 0
294
295 SlesKVersion() {}
296
297 SlesKVersion(version) {
298 this.parse(version)
299 }
300
301 static SlesKVersion minKVersion() {
302 return new SlesKVersion("rpm-0.0.0-0.0.0")
303 }
304
305 static SlesKVersion maxKVersion() {
306 return new SlesKVersion("rpm-" + Integer.MAX_VALUE + ".0.0-0.0.0")
307 }
308
309 static SlesKVersion factory(version) {
310 return new SlesKVersion(version)
311 }
312
313 def parse(version) {
314 this.major = 0
315 this.minor = 0
316 this.patch = 0
317 this.slesrelease = 0
318 this.slesmajor = 0
319 this.slesminor = 0
320
321 if (!version) {
322 throw new EmptyKVersionException("Empty kernel version")
323 }
324
325 // Eg. 5.14.21-150400.22
326 // Eg. 5.14.21-150400.24.100.2
327 // From tag: rpm-5.14.21-150400.24.100 -> 5.14.21-150400.24.100
328 def match = version =~ /^(rpm-)??(\d+)\.(\d+)\.(\d+)-(\d+)\.(\d+)(\.\d+)??$/
329 if (!match) {
330 throw new InvalidKVersionException("Invalid kernel version: ${version}")
331 }
332
333 this.major = Integer.parseInt(match.group(2))
334 this.minor = Integer.parseInt(match.group(3))
335 this.patch = Integer.parseInt(match.group(4))
336 this.slesrelease = Integer.parseInt(match.group(5))
337 this.slesmajor = Integer.parseInt(match.group(6))
338
339 if (match.group(7) != null) {
340 this.slesminor = Integer.parseInt(match.group(7).drop(1))
341 }
342 }
343
344 Boolean isRC() {
345 return false
346 }
347
348 Boolean isSameStable(SlesKVersion o) {
349 if (this.major != o.major) {
350 return false
351 }
352 if (this.minor != o.minor) {
353 return false
354 }
355 if (this.patch != o.patch) {
356 return false
357 }
358 if (this.slesrelease != o.slesrelease) {
359 return false
360 }
361 if (this.slesmajor != o.slesmajor) {
362 return false
363 }
364 if (this.slesminor != o.slesminor) {
365 return false
366 }
367 return true
368 }
369
370 @Override int compareTo(SlesKVersion o) {
371 if (this.major != o.major) {
372 return Integer.compare(this.major, o.major)
373 }
374 if (this.minor != o.minor) {
375 return Integer.compare(this.minor, o.minor)
376 }
377 if (this.patch != o.patch) {
378 return Integer.compare(this.patch, o.patch)
379 }
380 if (this.slesrelease != o.slesrelease) {
381 return Integer.compare(this.slesrelease, o.slesrelease)
382 }
383 if (this.slesmajor != o.slesmajor) {
384 return Integer.compare(this.slesmajor, o.slesmajor)
385 }
386 if (this.slesminor != o.slesminor) {
387 return Integer.compare(this.slesminor, o.slesminor)
388 }
389 return 0
390 }
391
392 String toString() {
393 String vString = "rpm-${this.major}.${this.minor}.${patch}-${this.slesrelease}.${this.slesmajor}"
394 if (this.slesminor != 0) {
395 vString = vString.concat(".${this.slesminor}")
396 }
397 return vString
398 }
399 }
400
401 class UbuntuKVersion implements Comparable<UbuntuKVersion> {
402
403 Integer major = 0
404 Integer minor = 0
405 Integer patch = 0
406 Integer umajor = 0
407 Integer uminor = 0
408 String suffix = ""
409 String strLTS = ""
410 Boolean isLTS = false
411
412 UbuntuKVersion() {}
413
414 UbuntuKVersion(version) {
415 this.parse(version)
416 }
417
418 static UbuntuKVersion minKVersion() {
419 return new UbuntuKVersion("Ubuntu-lts-0.0.0-0.0")
420 }
421
422 static UbuntuKVersion maxKVersion() {
423 return new UbuntuKVersion("Ubuntu-" + Integer.MAX_VALUE + ".0.0-0.0")
424 }
425
426 static UbuntuKVersion factory(version) {
427 return new UbuntuKVersion(version)
428 }
429
430 def parse(version) {
431 this.major = 0
432 this.minor = 0
433 this.patch = 0
434 this.umajor = 0
435 this.uminor = 0
436 this.suffix = "";
437 this.isLTS = false
438
439 if (!version) {
440 throw new EmptyKVersionException("Empty kernel version")
441 }
442
443 //'Ubuntu-hwe-5.8-5.8.0-19.20_20.04.3',
444 //'Ubuntu-lts-4.8.0-27.29_16.04.1',
445 //'Ubuntu-4.4.0-70.91',
446 def match = version =~ /^Ubuntu-(lts-|hwe-)??(?:\d+\.\d+-)??(\d+)\.(\d+)\.(\d+)-(\d+)\.(\d+)(.*)??$/
447 if (!match) {
448 throw new InvalidKVersionException("Invalid kernel version: ${version}")
449 }
450
451 if (match.group(1) != null) {
452 this.isLTS = true
453 this.strLTS = match.group(1)
454 }
455
456 // Major
457 this.major = Integer.parseInt(match.group(2))
458
459 // Minor
460 this.minor = Integer.parseInt(match.group(3))
461
462 // Patch level
463 this.patch = Integer.parseInt(match.group(4))
464
465 // Ubuntu major
466 this.umajor = Integer.parseInt(match.group(5))
467
468 // Ubuntu minor
469 this.uminor = Integer.parseInt(match.group(6))
470
471 if (match.group(7) != null) {
472 this.suffix = match.group(7)
473 }
474 }
475
476 // Return true if this version is a release candidate
477 Boolean isRC() {
478 return false
479 }
480
481 // Return true if both version are of the same stable branch
482 Boolean isSameStable(UbuntuKVersion o) {
483 if (this.isLTS != o.isLTS) {
484 return false
485 }
486 if (this.major != o.major) {
487 return false
488 }
489 if (this.minor != o.minor) {
490 return false
491 }
492 if (this.patch != o.patch) {
493 return false
494 }
495
496 return true
497 }
498
499 @Override int compareTo(UbuntuKVersion o) {
500 if (this.major != o.major) {
501 return Integer.compare(this.major, o.major)
502 }
503 if (this.minor != o.minor) {
504 return Integer.compare(this.minor, o.minor)
505 }
506 if (this.patch != o.patch) {
507 return Integer.compare(this.patch, o.patch)
508 }
509 if (this.umajor != o.umajor) {
510 return Integer.compare(this.umajor, o.umajor)
511 }
512 if (this.uminor != o.uminor) {
513 return Integer.compare(this.uminor, o.uminor)
514 }
515 if (this.isLTS != o.isLTS) {
516 if (o.isLTS) {
517 return 1
518 } else {
519 return -1
520 }
521 }
522
523 // Same version
524 return 0;
525 }
526
527 String toString() {
528 String vString = "Ubuntu-"
529
530 if (this.isLTS) {
531 vString = vString.concat("${this.strLTS}")
532 }
533
534 // The tag pattern changed for HWE kernels >= 5.0
535 if (this.isLTS && this.major >= 5) {
536 vString = vString.concat("${this.major}.${this.minor}-${this.major}.${this.minor}.${this.patch}-${this.umajor}.${this.uminor}${this.suffix}")
537 } else {
538 vString = vString.concat("${this.major}.${this.minor}.${this.patch}-${this.umajor}.${this.uminor}${this.suffix}")
539 }
540
541 return vString
542 }
543 }
544
545
546 // Retrieve parameters of the current build
547 def mbranch = build.getEnvironment(listener).get('GIT_BRANCH').minus('origin/')
548 def maxConcurrentBuild = build.buildVariableResolver.resolve('maxConcurrentBuild')
549 def kgitrepo = build.buildVariableResolver.resolve('kgitrepo')
550 def kverfloor_raw = build.buildVariableResolver.resolve('kverfloor')
551 def kverceil_raw = build.buildVariableResolver.resolve('kverceil')
552 def kverfilter = build.buildVariableResolver.resolve('kverfilter')
553 def kverrc = build.buildVariableResolver.resolve('kverrc')
554 def elversion = build.buildVariableResolver.resolve('elversion')
555 def slesversion = build.buildVariableResolver.resolve('slesversion')
556 def uversion = build.buildVariableResolver.resolve('uversion')
557 def job = Hudson.instance.getJob(build.buildVariableResolver.resolve('kbuildjob'))
558 def currentJobName = build.project.getFullDisplayName()
559 def gitmodpath = build.getEnvironment(listener).get('WORKSPACE') + "/src/lttng-modules"
560
561 // Get the out variable
562 def config = new HashMap()
563 def bindings = getBinding()
564 config.putAll(bindings.getVariables())
565 def out = config['out']
566
567
568 // Get the lttng-modules git url
569 def gitmodrepo = Git.open(new File(gitmodpath))
570 def mgitrepo = gitmodrepo.getRepository().getConfig().getString("remote", "origin", "url")
571
572 // Get tags from git repository
573 def refs = Git.lsRemoteRepository().setTags(true).setRemote(kgitrepo).call()
574
575 // Get kernel versions to build
576 def kversions = []
577 def kversionsRC = []
578 def matchStrs = []
579 def blacklist = []
580 def kversionFactory = ""
581 def distroversion = ""
582
583 if (elversion != null) {
584 distroversion = elversion
585 kversionFactory = new ElKVersion()
586 switch (elversion) {
587 case 'el8':
588 matchStrs = [
589 // EL 8 (all)
590 // ~/^refs\/tags\/(imports\/r8\/kernel-[\d\.-]+.el8.*)$/,
591 // EL 8.4
592 ~/^refs\/tags\/(imports\/r8\/kernel-4\.18\.0-305\.[\d\.-]+.el8.*)$/,
593 // EL 8.6
594 ~/^refs\/tags\/(imports\/r8\/kernel-4\.18\.0-372\.[\d\.-]+.el8.*)$/,
595 ]
596 blacklist = []
597 break
598 default:
599 println ("Unsupport EL version: ${elversion}")
600 throw new InterruptedException()
601 break
602 }
603 } else if (slesversion != null) {
604 distroversion = slesversion
605 kversionFactory = new SlesKVersion()
606 switch (slesversion) {
607 case 'sles15sp4':
608 matchStrs = [
609 ~/^refs\/tags\/(rpm-5.14.21-150400\.22(\.\d+)?(\.\d+)?)$/,
610 ~/^refs\/tags\/(rpm-5.14.21-150400\.24(\.\d+)?(\.\d+)?)$/,
611 ]
612 blacklist = [
613 // "Retracted", @see https://www.suse.com/support/kb/doc/?id=000019587#SLE15SP4
614 'rpm-5.14.21-150400.24.49',
615 'rpm-5.14.21-150400.24.84',
616 ]
617 break
618
619 default:
620 println "Unsupported SLES version: ${slesversion}"
621 throw new InterruptedException()
622 break
623 }
624 } else if (uversion != null) {
625 distroversion = uversion
626 kversionFactory = new UbuntuKVersion()
627 switch (uversion) {
628 case 'jammy':
629 matchStrs = [
630 ~/^refs\/tags\/(Ubuntu-5\.15\.0-\d{1,3}?\.[\d]+)$/,
631 ~/^refs\/tags\/(Ubuntu-hwe-6\.8-6\.8\.0-.*_22\.04\.\d+)$/,
632 ]
633 break
634
635 case 'focal':
636 matchStrs = [
637 ~/^refs\/tags\/(Ubuntu-5\.4\.0-\d{1,3}?\.[\d]+)$/,
638 ~/^refs\/tags\/(Ubuntu-hwe-5\.15-5\.15\.0-.*_20\.04\.\d+)$/,
639 ~/^refs\/tags\/(Ubuntu-hwe-6\.8-6\.8\.0-.*_20\.04\.\d+)$/,
640 ]
641 break
642
643 case 'noble':
644 matchStrs = [
645 ~/^refs\/tags\/(Ubuntu-6\.8\.0-\d{1,3}?\.[\d]+)$/,
646 ]
647 break
648
649 default:
650 println "Unsupported Ubuntu version: ${uversion}"
651 throw new InterruptedException()
652 break
653 }
654 } else {
655 // Vanilla
656 kversionFactory = new VanillaKVersion()
657 matchStrs = [
658 ~/^refs\/tags\/(v[\d\.]+(-rc(\d+))?)$/,
659 ]
660 blacklist = [
661 'v3.2.3',
662 ]
663 }
664
665 // Parse kernel versions
666 def kverfloor = ""
667 try {
668 kverfloor = kversionFactory.factory(kverfloor_raw)
669 } catch (EmptyKVersionException e) {
670 kverfloor = kversionFactory.minKVersion()
671 }
672
673 def kverceil = ""
674 try {
675 kverceil = kversionFactory.factory(kverceil_raw)
676 } catch (EmptyKVersionException e) {
677 kverceil = kversionFactory.maxKVersion()
678 }
679
680 // Build a sorted list of versions to build
681 for (ref in refs) {
682 for (matchStr in matchStrs) {
683 def match = ref.getName() =~ matchStr
684 if (match && !blacklist.contains(match.group(1))) {
685 def v = kversionFactory.factory(match.group(1))
686
687 if ((v >= kverfloor) && (v < kverceil)) {
688 if (v.isRC()) {
689 kversionsRC.add(v)
690 } else {
691 kversions.add(v)
692 }
693 }
694 }
695 }
696 }
697
698 // The filtering step assumes the version lists are sorted
699 kversions.sort()
700 kversionsRC.sort()
701
702 switch (kverfilter) {
703 case 'stable-head':
704 // Keep only the head of each stable branch
705 println('Filter kernel versions to keep only the latest point release of each stable branch.')
706
707 for (i = 0; i < kversions.size(); i++) {
708 def curr = kversions[i]
709 def next = i < kversions.size() - 1 ? kversions[i + 1] : null
710
711 if (next != null) {
712 if (curr.isSameStable(next)) {
713 kversions.remove(i)
714 i--
715 }
716 }
717 }
718 break
719
720 case 'lts-head':
721 // Keep only the head of each LTS branch and the latest non-RC tag
722 println('Filter kernel versions to keep only the latest point release of each lts branch and the current stable.')
723
724 def lts_kversions = []
725 // Old LTS entries are kept so that "lts-head" is still meaningful in kernel
726 // version ranges that are supported by lttng-modules but no longer supported
727 // upstream, eg. lttng-modules stable-2.13 supports >= 3.0
728 lts_kversions.add(kversionFactory.factory("v3.0")) // LTS until October 2013
729 lts_kversions.add(kversionFactory.factory("v3.2")) // LTS until May 2018
730 lts_kversions.add(kversionFactory.factory("v3.4")) // LTS until October 2016
731 lts_kversions.add(kversionFactory.factory("v3.10")) // LTS until November 2017
732 lts_kversions.add(kversionFactory.factory("v3.12")) // LTS until May 2017
733 lts_kversions.add(kversionFactory.factory("v3.14")) // LTS until August 2016
734 lts_kversions.add(kversionFactory.factory("v3.16")) // LTS until October 2014
735 lts_kversions.add(kversionFactory.factory("v3.18")) // LTS until January 2017
736 lts_kversions.add(kversionFactory.factory("v4.1")) // LTS until May 2018
737 lts_kversions.add(kversionFactory.factory("v4.4")) // SLTS until 2026
738 lts_kversions.add(kversionFactory.factory("v4.9")) // LTS until January 2023
739 lts_kversions.add(kversionFactory.factory("v4.14")) // LTS until January 2024
740 lts_kversions.add(kversionFactory.factory("v4.19")) // LTS until December 2024
741 lts_kversions.add(kversionFactory.factory("v5.4")) // LTS until December 2025
742 lts_kversions.add(kversionFactory.factory("v5.10")) // LTS until December 2026
743 lts_kversions.add(kversionFactory.factory("v5.15")) // LTS until December 2026
744 lts_kversions.add(kversionFactory.factory("v6.1")) // LTS until December 2026
745 lts_kversions.add(kversionFactory.factory("v6.6")) // LTS until December 2026
746
747 // First filter the head of each branch
748 for (i = 0; i < kversions.size(); i++) {
749 def curr = kversions[i]
750 def next = i < kversions.size() - 1 ? kversions[i + 1] : null
751
752 if (next != null) {
753 if (curr.isSameStable(next)) {
754 kversions.remove(i)
755 i--
756 }
757 }
758 }
759
760 for (i = 0; i < kversions.size(); i++) {
761 def curr = kversions[i]
762
763 // Keep the newest tag
764 if (i == kversions.size() - 1) {
765 break
766 }
767
768 // Prune non-LTS versions
769 def keep = false
770 for (j = 0; j < lts_kversions.size(); j++) {
771 if (curr.isSameStable(lts_kversions[j])) {
772 keep = true
773 break
774 }
775 }
776
777 if (!keep) {
778 kversions.remove(i)
779 i--
780 }
781 }
782 break
783
784 default:
785 // No filtering of kernel versions
786 println('No kernel versions filtering selected.')
787 break
788 }
789
790 if (kverrc == "true") {
791 // If the last RC version is newer than the last stable, add it to the build list
792 if (kversionsRC.size() > 0 && kversionsRC.last() > kversions.last()) {
793 kversions.add(kversionsRC.last())
794 }
795 }
796
797 println "Building the following kernel versions:"
798 for (k in kversions) {
799 println k
800 }
801
802 // Debug: Stop build here
803 //throw new InterruptedException()
804
805 def joburl = HyperlinkNote.encodeTo('/' + job.url, job.fullDisplayName)
806
807 def allBuilds = []
808 def ongoingBuild = []
809 def failedRuns = []
810 def isFailed = false
811 def similarJobQueued = 0;
812
813 // Loop while we have kernel versions remaining or jobs running
814 while ( kversions.size() != 0 || ongoingBuild.size() != 0 ) {
815
816 if(ongoingBuild.size() < maxConcurrentBuild.toInteger() && kversions.size() != 0) {
817 def kversion = kversions.pop()
818 def job_params = [
819 new StringParameterValue('mversion', mbranch),
820 new StringParameterValue('mgitrepo', mgitrepo),
821 new StringParameterValue('ktag', kversion.toString()),
822 new StringParameterValue('kgitrepo', kgitrepo),
823 new StringParameterValue('distroversion', distroversion),
824 new StringParameterValue('getsrc_repo', build.buildVariableResolver.resolve('getsrc_repo')),
825 new StringParameterValue('getsrc_version', build.buildVariableResolver.resolve('getsrc_version'))
826 ]
827
828 // Launch the parametrized build
829 def param_build = job.scheduleBuild2(0, new Cause.UpstreamCause(build), new ParametersAction(job_params))
830 println "triggering ${joburl} for the ${mbranch} branch on kernel ${kversion}"
831
832 // Add it to the ongoing build queue
833 ongoingBuild.push(param_build)
834
835 } else {
836
837 println "Waiting... Queued: " + kversions.size() + " Running: " + ongoingBuild.size()
838 try {
839 Thread.sleep(10000)
840 } catch(e) {
841 if (e in InterruptedException) {
842 build.setResult(hudson.model.Result.ABORTED)
843 throw new InterruptedException()
844 } else {
845 throw(e)
846 }
847 }
848
849 // Abort job if a newer instance is queued
850 if (!currentJobName.contains("gerrit")) {
851 similarJobQueued = Hudson.instance.queue.items.count{it.task.getFullDisplayName() == currentJobName}
852 if (similarJobQueued > 0) {
853 println "Abort, a newer instance of the job was queued"
854 build.setResult(hudson.model.Result.ABORTED)
855 throw new InterruptedException()
856 }
857 }
858
859 def i = ongoingBuild.iterator()
860 while ( i.hasNext() ) {
861 currentBuild = i.next()
862 if ( currentBuild.isCancelled() || currentBuild.isDone() ) {
863 // Remove from queue
864 i.remove()
865
866 // Print results
867 def matrixParent = currentBuild.get()
868 allBuilds.add(matrixParent)
869 def kernelStr = matrixParent.buildVariableResolver.resolve("ktag")
870 println "${matrixParent.fullDisplayName} (${kernelStr}) completed with status ${matrixParent.result}"
871
872 // Process child runs of matrixBuild
873 def childRuns = matrixParent.getRuns()
874 for ( childRun in childRuns ) {
875 println "\t${childRun.fullDisplayName} (${kernelStr}) completed with status ${childRun.result}"
876 if (childRun.result != Result.SUCCESS) {
877 failedRuns.add(childRun)
878 isFailed = true
879 }
880 }
881 }
882 }
883 }
884 }
885
886 // Get log of failed runs
887 for (failedRun in failedRuns) {
888 println "---START---"
889 failedRun.writeWholeLogTo(out)
890 println "---END---"
891 }
892
893 println "---Build report---"
894 for (b in allBuilds) {
895 def kernelStr = b.buildVariableResolver.resolve("ktag")
896 println "${b.fullDisplayName} (${kernelStr}) completed with status ${b.result}"
897 // Cleanup builds
898 try {
899 b.delete()
900 } catch (all) {}
901 }
902
903 // Mark this build failed if any child build has failed
904 if (isFailed) {
905 build.setResult(hudson.model.Result.FAILURE)
906 }
907
908 // EOF
This page took 0.048584 seconds and 5 git commands to generate.