2 * Copyright (C) 2016-2020 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 class InvalidKVersionException extends Exception {
27 public InvalidKVersionException(String message) {
32 class EmptyKVersionException extends Exception {
33 public EmptyKVersionException(String message) {
38 class VanillaKVersion implements Comparable<VanillaKVersion> {
44 Integer rc = Integer.MAX_VALUE
48 VanillaKVersion(version) {
52 static VanillaKVersion minKVersion() {
53 return new VanillaKVersion("v0.0.0")
56 static VanillaKVersion maxKVersion() {
57 return new VanillaKVersion("v" + Integer.MAX_VALUE + ".0.0")
60 static VanillaKVersion factory(version) {
61 return new VanillaKVersion(version)
69 this.rc = Integer.MAX_VALUE
72 throw new EmptyKVersionException("Empty kernel version")
75 def match = version =~ /^v(\d+)\.(\d+)(\.(\d+))?(\.(\d+))?(-rc(\d+))?$/
77 throw new InvalidKVersionException("Invalid kernel version: ${version}")
83 this.major = Integer.parseInt(match.group(1))
84 if (this.major <= 2) {
86 this.majorB = Integer.parseInt(match.group(2))
90 if (match.group(2 + offset) != null) {
91 this.minor = Integer.parseInt(match.group(2 + offset))
95 if (match.group(4 + offset) != null) {
96 this.patch = Integer.parseInt(match.group(4 + offset))
100 if (match.group(8) != null) {
101 this.rc = Integer.parseInt(match.group(8))
105 // Return true if this version is a release candidate
107 return this.rc != Integer.MAX_VALUE
110 // Return true if both version are of the same stable branch
111 Boolean isSameStable(VanillaKVersion o) {
112 if (this.major != o.major) {
115 if (this.majorB != o.majorB) {
118 if (this.minor != o.minor) {
125 @Override int compareTo(VanillaKVersion o) {
126 if (this.major != o.major) {
127 return Integer.compare(this.major, o.major)
129 if (this.majorB != o.majorB) {
130 return Integer.compare(this.majorB, o.majorB)
132 if (this.minor != o.minor) {
133 return Integer.compare(this.minor, o.minor)
135 if (this.patch != o.patch) {
136 return Integer.compare(this.patch, o.patch)
138 if (this.rc != o.rc) {
139 return Integer.compare(this.rc, o.rc)
147 String vString = "v${this.major}"
149 if (this.majorB > 0) {
150 vString = vString.concat(".${this.majorB}")
153 vString = vString.concat(".${this.minor}")
155 if (this.patch > 0) {
156 vString = vString.concat(".${this.patch}")
159 if (this.rc > 0 && this.rc < Integer.MAX_VALUE) {
160 vString = vString.concat("-rc${this.rc}")
166 class ElKVersion implements Comparable<ElKVersion> {
173 Integer el_release_major = 0
174 Integer el_release_minor = 0
175 Boolean append_zero_el_release_minor = false
176 String version_prefix = ""
180 ElKVersion(version) {
184 static ElKVersion minKVersion() {
185 return new ElKVersion("kernel-0.0.0-0.0.0.el0_0")
188 static ElKVersion maxKVersion() {
189 return new ElKVersion("kernel-" + Integer.MAX_VALUE + ".0.0-0.0.0.el0_0")
192 static ElKVersion factory(version) {
193 return new ElKVersion(version)
203 this.el_release_major = 0
204 this.el_release_minor = 0
205 this.append_zero_el_release_minor = false
206 this.version_prefix = ""
209 throw new EmptyKVersionException("Empty kernel version")
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+))??$/
219 throw new InvalidKVersionException("Invalid kernel version: ${version}")
222 if (match.group(1)) {
223 this.version_prefix = match.group(1)
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))
232 if (match.group(9)) {
233 this.elpatch = Integer.parseInt(match.group(9))
235 if (match.group(10)) {
236 this.el_release_major = Integer.parseInt(match.group(10))
238 if (match.group(12)) {
239 this.el_release_minor = Integer.parseInt(match.group(12))
240 this.append_zero_el_release_minor = true
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") {
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")
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}")
274 if (this.elpatch != 0) {
275 vString = vString.concat(".${this.elpatch}")
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}")
287 class SlesKVersion implements Comparable<SlesKVersion> {
291 Integer slesrelease = 0
292 Integer slesmajor = 0
293 Integer slesminor = 0
297 SlesKVersion(version) {
301 static SlesKVersion minKVersion() {
302 return new SlesKVersion("rpm-0.0.0-0.0.0")
305 static SlesKVersion maxKVersion() {
306 return new SlesKVersion("rpm-" + Integer.MAX_VALUE + ".0.0-0.0.0")
309 static SlesKVersion factory(version) {
310 return new SlesKVersion(version)
322 throw new EmptyKVersionException("Empty kernel version")
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+)??$/
330 throw new InvalidKVersionException("Invalid kernel version: ${version}")
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))
339 if (match.group(7) != null) {
340 this.slesminor = Integer.parseInt(match.group(7).drop(1))
348 Boolean isSameStable(SlesKVersion o) {
349 if (this.major != o.major) {
352 if (this.minor != o.minor) {
355 if (this.patch != o.patch) {
358 if (this.slesrelease != o.slesrelease) {
361 if (this.slesmajor != o.slesmajor) {
364 if (this.slesminor != o.slesminor) {
370 @Override int compareTo(SlesKVersion o) {
371 if (this.major != o.major) {
372 return Integer.compare(this.major, o.major)
374 if (this.minor != o.minor) {
375 return Integer.compare(this.minor, o.minor)
377 if (this.patch != o.patch) {
378 return Integer.compare(this.patch, o.patch)
380 if (this.slesrelease != o.slesrelease) {
381 return Integer.compare(this.slesrelease, o.slesrelease)
383 if (this.slesmajor != o.slesmajor) {
384 return Integer.compare(this.slesmajor, o.slesmajor)
386 if (this.slesminor != o.slesminor) {
387 return Integer.compare(this.slesminor, o.slesminor)
393 String vString = "rpm-${this.major}.${this.minor}.${patch}-${this.slesrelease}.${this.slesmajor}"
394 if (this.slesminor != 0) {
395 vString = vString.concat(".${this.slesminor}")
401 class UbuntuKVersion implements Comparable<UbuntuKVersion> {
410 Boolean isLTS = false
414 UbuntuKVersion(version) {
418 static UbuntuKVersion minKVersion() {
419 return new UbuntuKVersion("Ubuntu-lts-0.0.0-0.0")
422 static UbuntuKVersion maxKVersion() {
423 return new UbuntuKVersion("Ubuntu-" + Integer.MAX_VALUE + ".0.0-0.0")
426 static UbuntuKVersion factory(version) {
427 return new UbuntuKVersion(version)
440 throw new EmptyKVersionException("Empty kernel version")
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+)(.*)??$/
448 throw new InvalidKVersionException("Invalid kernel version: ${version}")
451 if (match.group(1) != null) {
453 this.strLTS = match.group(1)
457 this.major = Integer.parseInt(match.group(2))
460 this.minor = Integer.parseInt(match.group(3))
463 this.patch = Integer.parseInt(match.group(4))
466 this.umajor = Integer.parseInt(match.group(5))
469 this.uminor = Integer.parseInt(match.group(6))
471 if (match.group(7) != null) {
472 this.suffix = match.group(7)
476 // Return true if this version is a release candidate
481 // Return true if both version are of the same stable branch
482 Boolean isSameStable(UbuntuKVersion o) {
483 if (this.isLTS != o.isLTS) {
486 if (this.major != o.major) {
489 if (this.minor != o.minor) {
492 if (this.patch != o.patch) {
499 @Override int compareTo(UbuntuKVersion o) {
500 if (this.major != o.major) {
501 return Integer.compare(this.major, o.major)
503 if (this.minor != o.minor) {
504 return Integer.compare(this.minor, o.minor)
506 if (this.patch != o.patch) {
507 return Integer.compare(this.patch, o.patch)
509 if (this.umajor != o.umajor) {
510 return Integer.compare(this.umajor, o.umajor)
512 if (this.uminor != o.uminor) {
513 return Integer.compare(this.uminor, o.uminor)
515 if (this.isLTS != o.isLTS) {
528 String vString = "Ubuntu-"
531 vString = vString.concat("${this.strLTS}")
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}")
538 vString = vString.concat("${this.major}.${this.minor}.${this.patch}-${this.umajor}.${this.uminor}${this.suffix}")
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"
561 // Get the out variable
562 def config = new HashMap()
563 def bindings = getBinding()
564 config.putAll(bindings.getVariables())
565 def out = config['out']
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")
572 // Get tags from git repository
573 def refs = Git.lsRemoteRepository().setTags(true).setRemote(kgitrepo).call()
575 // Get kernel versions to build
580 def kversionFactory = ""
581 def distroversion = ""
583 if (elversion != null) {
584 distroversion = elversion
585 kversionFactory = new ElKVersion()
590 // ~/^refs\/tags\/(imports\/r8\/kernel-[\d\.-]+.el8.*)$/,
592 ~/^refs\/tags\/(imports\/r8\/kernel-4\.18\.0-305\.[\d\.-]+.el8.*)$/,
594 ~/^refs\/tags\/(imports\/r8\/kernel-4\.18\.0-372\.[\d\.-]+.el8.*)$/,
599 println ("Unsupport EL version: ${elversion}")
600 throw new InterruptedException()
603 } else if (slesversion != null) {
604 distroversion = slesversion
605 kversionFactory = new SlesKVersion()
606 switch (slesversion) {
609 ~/^refs\/tags\/(rpm-5.14.21-150400\.22(\.\d+)?(\.\d+)?)$/,
610 ~/^refs\/tags\/(rpm-5.14.21-150400\.24(\.\d+)?(\.\d+)?)$/,
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',
620 println "Unsupported SLES version: ${slesversion}"
621 throw new InterruptedException()
624 } else if (uversion != null) {
625 distroversion = uversion
626 kversionFactory = new UbuntuKVersion()
630 ~/^refs\/tags\/(Ubuntu-5\.15\.0-\d{1,3}?\.[\d]+)$/,
631 ~/^refs\/tags\/(Ubuntu-hwe-6\.2-6\.2\.0-.*_22\.04\.\d+)$/,
632 ~/^refs\/tags\/(Ubuntu-hwe-6\.5-6\.5\.0-.*_22\.04\.\d+)$/,
638 ~/^refs\/tags\/(Ubuntu-5\.4\.0-\d{1,3}?\.[\d]+)$/,
639 ~/^refs\/tags\/(Ubuntu-hwe-5\.13-5\.13\.0-.*_20\.04\.\d+)$/,
640 ~/^refs\/tags\/(Ubuntu-hwe-5\.15-5\.15\.0-.*_20\.04\.\d+)$/,
646 ~/^refs\/tags\/(Ubuntu-6\.8\.0-\d{1,3}?\.[\d]+)$/,
651 println "Unsupported Ubuntu version: ${uversion}"
652 throw new InterruptedException()
657 kversionFactory = new VanillaKVersion()
659 ~/^refs\/tags\/(v[\d\.]+(-rc(\d+))?)$/,
666 // Parse kernel versions
669 kverfloor = kversionFactory.factory(kverfloor_raw)
670 } catch (EmptyKVersionException e) {
671 kverfloor = kversionFactory.minKVersion()
676 kverceil = kversionFactory.factory(kverceil_raw)
677 } catch (EmptyKVersionException e) {
678 kverceil = kversionFactory.maxKVersion()
681 // Build a sorted list of versions to build
683 for (matchStr in matchStrs) {
684 def match = ref.getName() =~ matchStr
685 if (match && !blacklist.contains(match.group(1))) {
686 def v = kversionFactory.factory(match.group(1))
688 if ((v >= kverfloor) && (v < kverceil)) {
699 // The filtering step assumes the version lists are sorted
703 switch (kverfilter) {
705 // Keep only the head of each stable branch
706 println('Filter kernel versions to keep only the latest point release of each stable branch.')
708 for (i = 0; i < kversions.size(); i++) {
709 def curr = kversions[i]
710 def next = i < kversions.size() - 1 ? kversions[i + 1] : null
713 if (curr.isSameStable(next)) {
722 // Keep only the head of each LTS branch and the latest non-RC tag
723 println('Filter kernel versions to keep only the latest point release of each lts branch and the current stable.')
725 def lts_kversions = []
726 // Old LTS entries are kept so that "lts-head" is still meaningful in kernel
727 // version ranges that are supported by lttng-modules but no longer supported
728 // upstream, eg. lttng-modules stable-2.13 supports >= 3.0
729 lts_kversions.add(kversionFactory.factory("v3.0")) // LTS until October 2013
730 lts_kversions.add(kversionFactory.factory("v3.2")) // LTS until May 2018
731 lts_kversions.add(kversionFactory.factory("v3.4")) // LTS until October 2016
732 lts_kversions.add(kversionFactory.factory("v3.10")) // LTS until November 2017
733 lts_kversions.add(kversionFactory.factory("v3.12")) // LTS until May 2017
734 lts_kversions.add(kversionFactory.factory("v3.14")) // LTS until August 2016
735 lts_kversions.add(kversionFactory.factory("v3.16")) // LTS until October 2014
736 lts_kversions.add(kversionFactory.factory("v3.18")) // LTS until January 2017
737 lts_kversions.add(kversionFactory.factory("v4.1")) // LTS until May 2018
738 lts_kversions.add(kversionFactory.factory("v4.4")) // SLTS until 2026
739 lts_kversions.add(kversionFactory.factory("v4.9")) // LTS until January 2023
740 lts_kversions.add(kversionFactory.factory("v4.14")) // LTS until January 2024
741 lts_kversions.add(kversionFactory.factory("v4.19")) // LTS until December 2024
742 lts_kversions.add(kversionFactory.factory("v5.4")) // LTS until December 2025
743 lts_kversions.add(kversionFactory.factory("v5.10")) // LTS until December 2026
744 lts_kversions.add(kversionFactory.factory("v5.15")) // LTS until December 2026
745 lts_kversions.add(kversionFactory.factory("v6.1")) // LTS until December 2026
746 lts_kversions.add(kversionFactory.factory("v6.6")) // LTS until December 2026
748 // First filter the head of each branch
749 for (i = 0; i < kversions.size(); i++) {
750 def curr = kversions[i]
751 def next = i < kversions.size() - 1 ? kversions[i + 1] : null
754 if (curr.isSameStable(next)) {
761 for (i = 0; i < kversions.size(); i++) {
762 def curr = kversions[i]
764 // Keep the newest tag
765 if (i == kversions.size() - 1) {
769 // Prune non-LTS versions
771 for (j = 0; j < lts_kversions.size(); j++) {
772 if (curr.isSameStable(lts_kversions[j])) {
786 // No filtering of kernel versions
787 println('No kernel versions filtering selected.')
791 if (kverrc == "true") {
792 // If the last RC version is newer than the last stable, add it to the build list
793 if (kversionsRC.size() > 0 && kversionsRC.last() > kversions.last()) {
794 kversions.add(kversionsRC.last())
798 println "Building the following kernel versions:"
799 for (k in kversions) {
803 // Debug: Stop build here
804 //throw new InterruptedException()
806 def joburl = HyperlinkNote.encodeTo('/' + job.url, job.fullDisplayName)
809 def ongoingBuild = []
812 def similarJobQueued = 0;
814 // Loop while we have kernel versions remaining or jobs running
815 while ( kversions.size() != 0 || ongoingBuild.size() != 0 ) {
817 if(ongoingBuild.size() < maxConcurrentBuild.toInteger() && kversions.size() != 0) {
818 def kversion = kversions.pop()
820 new StringParameterValue('mversion', mbranch),
821 new StringParameterValue('mgitrepo', mgitrepo),
822 new StringParameterValue('ktag', kversion.toString()),
823 new StringParameterValue('kgitrepo', kgitrepo),
824 new StringParameterValue('distroversion', distroversion),
825 new StringParameterValue('getsrc_repo', build.buildVariableResolver.resolve('getsrc_repo')),
826 new StringParameterValue('getsrc_version', build.buildVariableResolver.resolve('getsrc_version'))
829 // Launch the parametrized build
830 def param_build = job.scheduleBuild2(0, new Cause.UpstreamCause(build), new ParametersAction(job_params))
831 println "triggering ${joburl} for the ${mbranch} branch on kernel ${kversion}"
833 // Add it to the ongoing build queue
834 ongoingBuild.push(param_build)
838 println "Waiting... Queued: " + kversions.size() + " Running: " + ongoingBuild.size()
842 if (e in InterruptedException) {
843 build.setResult(hudson.model.Result.ABORTED)
844 throw new InterruptedException()
850 // Abort job if a newer instance is queued
851 if (!currentJobName.contains("gerrit")) {
852 similarJobQueued = Hudson.instance.queue.items.count{it.task.getFullDisplayName() == currentJobName}
853 if (similarJobQueued > 0) {
854 println "Abort, a newer instance of the job was queued"
855 build.setResult(hudson.model.Result.ABORTED)
856 throw new InterruptedException()
860 def i = ongoingBuild.iterator()
861 while ( i.hasNext() ) {
862 currentBuild = i.next()
863 if ( currentBuild.isCancelled() || currentBuild.isDone() ) {
868 def matrixParent = currentBuild.get()
869 allBuilds.add(matrixParent)
870 def kernelStr = matrixParent.buildVariableResolver.resolve("ktag")
871 println "${matrixParent.fullDisplayName} (${kernelStr}) completed with status ${matrixParent.result}"
873 // Process child runs of matrixBuild
874 def childRuns = matrixParent.getRuns()
875 for ( childRun in childRuns ) {
876 println "\t${childRun.fullDisplayName} (${kernelStr}) completed with status ${childRun.result}"
877 if (childRun.result != Result.SUCCESS) {
878 failedRuns.add(childRun)
887 // Get log of failed runs
888 for (failedRun in failedRuns) {
889 println "---START---"
890 failedRun.writeWholeLogTo(out)
894 println "---Build report---"
895 for (b in allBuilds) {
896 def kernelStr = b.buildVariableResolver.resolve("ktag")
897 println "${b.fullDisplayName} (${kernelStr}) completed with status ${b.result}"
904 // Mark this build failed if any child build has failed
906 build.setResult(hudson.model.Result.FAILURE)