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 SlesKVersion implements Comparable<SlesKVersion> {
170 Integer slesrelease = 0
171 Integer slesmajor = 0
172 Integer slesminor = 0
176 SlesKVersion(version) {
180 static SlesKVersion minKVersion() {
181 return new SlesKVersion("rpm-0.0.0-0.0.0")
184 static SlesKVersion maxKVersion() {
185 return new SlesKVersion("rpm-" + Integer.MAX_VALUE + ".0.0-0.0.0")
188 static SlesKVersion factory(version) {
189 return new SlesKVersion(version)
201 throw new EmptyKVersionException("Empty kernel version")
204 // Eg. 5.14.21-150400.22
205 // Eg. 5.14.21-150400.24.100.2
206 // From tag: rpm-5.14.21-150400.24.100 -> 5.14.21-150400.24.100
207 def match = version =~ /^(rpm-)??(\d+)\.(\d+)\.(\d+)-(\d+)\.(\d+)(\.\d+)??$/
209 throw new InvalidKVersionException("Invalid kernel version: ${version}")
212 this.major = Integer.parseInt(match.group(2))
213 this.minor = Integer.parseInt(match.group(3))
214 this.patch = Integer.parseInt(match.group(4))
215 this.slesrelease = Integer.parseInt(match.group(5))
216 this.slesmajor = Integer.parseInt(match.group(6))
218 if (match.group(7) != null) {
219 this.slesminor = Integer.parseInt(match.group(7).drop(1))
227 Boolean isSameStable(SlesKVersion o) {
228 if (this.major != o.major) {
231 if (this.minor != o.minor) {
234 if (this.patch != o.patch) {
237 if (this.slesrelease != o.slesrelease) {
240 if (this.slesmajor != o.slesmajor) {
243 if (this.slesminor != o.slesminor) {
249 @Override int compareTo(SlesKVersion o) {
250 if (this.major != o.major) {
251 return Integer.compare(this.major, o.major)
253 if (this.minor != o.minor) {
254 return Integer.compare(this.minor, o.minor)
256 if (this.patch != o.patch) {
257 return Integer.compare(this.patch, o.patch)
259 if (this.slesrelease != o.slesrelease) {
260 return Integer.compare(this.slesrelease, o.slesrelease)
262 if (this.slesmajor != o.slesmajor) {
263 return Integer.compare(this.slesmajor, o.slesmajor)
265 if (this.slesminor != o.slesminor) {
266 return Integer.compare(this.slesminor, o.slesminor)
272 String vString = "rpm-${this.major}.${this.minor}.${patch}-${this.slesrelease}.${this.slesmajor}"
273 if (this.slesminor != 0) {
274 vString = vString.concat(".${this.slesminor}")
280 class UbuntuKVersion implements Comparable<UbuntuKVersion> {
289 Boolean isLTS = false
293 UbuntuKVersion(version) {
297 static UbuntuKVersion minKVersion() {
298 return new UbuntuKVersion("Ubuntu-lts-0.0.0-0.0")
301 static UbuntuKVersion maxKVersion() {
302 return new UbuntuKVersion("Ubuntu-" + Integer.MAX_VALUE + ".0.0-0.0")
305 static UbuntuKVersion factory(version) {
306 return new UbuntuKVersion(version)
319 throw new EmptyKVersionException("Empty kernel version")
322 //'Ubuntu-hwe-5.8-5.8.0-19.20_20.04.3',
323 //'Ubuntu-lts-4.8.0-27.29_16.04.1',
324 //'Ubuntu-4.4.0-70.91',
325 def match = version =~ /^Ubuntu-(lts-|hwe-)??(?:\d+\.\d+-)??(\d+)\.(\d+)\.(\d+)-(\d+)\.(\d+)(.*)??$/
327 throw new InvalidKVersionException("Invalid kernel version: ${version}")
330 if (match.group(1) != null) {
332 this.strLTS = match.group(1)
336 this.major = Integer.parseInt(match.group(2))
339 this.minor = Integer.parseInt(match.group(3))
342 this.patch = Integer.parseInt(match.group(4))
345 this.umajor = Integer.parseInt(match.group(5))
348 this.uminor = Integer.parseInt(match.group(6))
350 if (match.group(7) != null) {
351 this.suffix = match.group(7)
355 // Return true if this version is a release candidate
360 // Return true if both version are of the same stable branch
361 Boolean isSameStable(UbuntuKVersion o) {
362 if (this.isLTS != o.isLTS) {
365 if (this.major != o.major) {
368 if (this.minor != o.minor) {
371 if (this.patch != o.patch) {
378 @Override int compareTo(UbuntuKVersion o) {
379 if (this.major != o.major) {
380 return Integer.compare(this.major, o.major)
382 if (this.minor != o.minor) {
383 return Integer.compare(this.minor, o.minor)
385 if (this.patch != o.patch) {
386 return Integer.compare(this.patch, o.patch)
388 if (this.umajor != o.umajor) {
389 return Integer.compare(this.umajor, o.umajor)
391 if (this.uminor != o.uminor) {
392 return Integer.compare(this.uminor, o.uminor)
394 if (this.isLTS != o.isLTS) {
407 String vString = "Ubuntu-"
410 vString = vString.concat("${this.strLTS}")
413 // The tag pattern changed for HWE kernels >= 5.0
414 if (this.isLTS && this.major >= 5) {
415 vString = vString.concat("${this.major}.${this.minor}-${this.major}.${this.minor}.${this.patch}-${this.umajor}.${this.uminor}${this.suffix}")
417 vString = vString.concat("${this.major}.${this.minor}.${this.patch}-${this.umajor}.${this.uminor}${this.suffix}")
425 // Retrieve parameters of the current build
426 def mbranch = build.getEnvironment(listener).get('GIT_BRANCH').minus('origin/')
427 def maxConcurrentBuild = build.buildVariableResolver.resolve('maxConcurrentBuild')
428 def kgitrepo = build.buildVariableResolver.resolve('kgitrepo')
429 def kverfloor_raw = build.buildVariableResolver.resolve('kverfloor')
430 def kverceil_raw = build.buildVariableResolver.resolve('kverceil')
431 def kverfilter = build.buildVariableResolver.resolve('kverfilter')
432 def kverrc = build.buildVariableResolver.resolve('kverrc')
433 def slesversion = build.buildVariableResolver.resolve('slesversion')
434 def uversion = build.buildVariableResolver.resolve('uversion')
435 def job = Hudson.instance.getJob(build.buildVariableResolver.resolve('kbuildjob'))
436 def currentJobName = build.project.getFullDisplayName()
437 def gitmodpath = build.getEnvironment(listener).get('WORKSPACE') + "/src/lttng-modules"
439 // Get the out variable
440 def config = new HashMap()
441 def bindings = getBinding()
442 config.putAll(bindings.getVariables())
443 def out = config['out']
446 // Get the lttng-modules git url
447 def gitmodrepo = Git.open(new File(gitmodpath))
448 def mgitrepo = gitmodrepo.getRepository().getConfig().getString("remote", "origin", "url")
450 // Get tags from git repository
451 def refs = Git.lsRemoteRepository().setTags(true).setRemote(kgitrepo).call()
453 // Get kernel versions to build
458 def kversionFactory = ""
460 if (slesversion != null) {
461 kversionFactory = new SlesKVersion()
462 switch (slesversion) {
465 ~/^refs\/tags\/(rpm-5.14.21-150400\.22(\.\d+)?(\.\d+)?)$/,
466 ~/^refs\/tags\/(rpm-5.14.21-150400\.24(\.\d+)?(\.\d+)?)$/,
469 // "Retracted", @see https://www.suse.com/support/kb/doc/?id=000019587#SLE15SP4
470 'rpm-5.14.21-150400.24.49',
471 'rpm-5.14.21-150400.24.84',
476 println "Unsupported SLES version: ${slesversion}"
477 throw new InterruptedException()
480 } else if (uversion != null) {
481 kversionFactory = new UbuntuKVersion()
485 ~/^refs\/tags\/(Ubuntu-5\.15\.0-\d{1,3}?\.[\d]+)$/,
486 ~/^refs\/tags\/(Ubuntu-hwe-6\.2-6\.2\.0-.*_22\.04\.\d+)$/,
487 ~/^refs\/tags\/(Ubuntu-hwe-6\.5-6\.5\.0-.*_22\.04\.\d+)$/,
493 ~/^refs\/tags\/(Ubuntu-5\.4\.0-\d{1,3}?\.[\d]+)$/,
494 ~/^refs\/tags\/(Ubuntu-hwe-5\.13-5\.13\.0-.*_20\.04\.\d+)$/,
495 ~/^refs\/tags\/(Ubuntu-hwe-5\.15-5\.15\.0-.*_20\.04\.\d+)$/,
501 ~/^refs\/tags\/(Ubuntu-6\.8\.0-\d{1,3}?\.[\d]+)$/,
506 println "Unsupported Ubuntu version: ${uversion}"
507 throw new InterruptedException()
512 kversionFactory = new VanillaKVersion()
514 ~/^refs\/tags\/(v[\d\.]+(-rc(\d+))?)$/,
521 // Parse kernel versions
524 kverfloor = kversionFactory.factory(kverfloor_raw)
525 } catch (EmptyKVersionException e) {
526 kverfloor = kversionFactory.minKVersion()
531 kverceil = kversionFactory.factory(kverceil_raw)
532 } catch (EmptyKVersionException e) {
533 kverceil = kversionFactory.maxKVersion()
536 // Build a sorted list of versions to build
538 for (matchStr in matchStrs) {
539 def match = ref.getName() =~ matchStr
540 if (match && !blacklist.contains(match.group(1))) {
541 def v = kversionFactory.factory(match.group(1))
543 if ((v >= kverfloor) && (v < kverceil)) {
554 // The filtering step assumes the version lists are sorted
558 switch (kverfilter) {
560 // Keep only the head of each stable branch
561 println('Filter kernel versions to keep only the latest point release of each stable branch.')
563 for (i = 0; i < kversions.size(); i++) {
564 def curr = kversions[i]
565 def next = i < kversions.size() - 1 ? kversions[i + 1] : null
568 if (curr.isSameStable(next)) {
577 // Keep only the head of each LTS branch and the latest non-RC tag
578 println('Filter kernel versions to keep only the latest point release of each lts branch and the current stable.')
580 def lts_kversions = []
581 // Old LTS entries are kept so that "lts-head" is still meaningful in kernel
582 // version ranges that are supported by lttng-modules but no longer supported
583 // upstream, eg. lttng-modules stable-2.13 supports >= 3.0
584 lts_kversions.add(kversionFactory.factory("v3.0")) // LTS until October 2013
585 lts_kversions.add(kversionFactory.factory("v3.2")) // LTS until May 2018
586 lts_kversions.add(kversionFactory.factory("v3.4")) // LTS until October 2016
587 lts_kversions.add(kversionFactory.factory("v3.10")) // LTS until November 2017
588 lts_kversions.add(kversionFactory.factory("v3.12")) // LTS until May 2017
589 lts_kversions.add(kversionFactory.factory("v3.14")) // LTS until August 2016
590 lts_kversions.add(kversionFactory.factory("v3.16")) // LTS until October 2014
591 lts_kversions.add(kversionFactory.factory("v3.18")) // LTS until January 2017
592 lts_kversions.add(kversionFactory.factory("v4.1")) // LTS until May 2018
593 lts_kversions.add(kversionFactory.factory("v4.4")) // SLTS until 2026
594 lts_kversions.add(kversionFactory.factory("v4.9")) // LTS until January 2023
595 lts_kversions.add(kversionFactory.factory("v4.14")) // LTS until January 2024
596 lts_kversions.add(kversionFactory.factory("v4.19")) // LTS until December 2024
597 lts_kversions.add(kversionFactory.factory("v5.4")) // LTS until December 2025
598 lts_kversions.add(kversionFactory.factory("v5.10")) // LTS until December 2026
599 lts_kversions.add(kversionFactory.factory("v5.15")) // LTS until December 2026
600 lts_kversions.add(kversionFactory.factory("v6.1")) // LTS until December 2026
601 lts_kversions.add(kversionFactory.factory("v6.6")) // LTS until December 2026
603 // First filter the head of each branch
604 for (i = 0; i < kversions.size(); i++) {
605 def curr = kversions[i]
606 def next = i < kversions.size() - 1 ? kversions[i + 1] : null
609 if (curr.isSameStable(next)) {
616 for (i = 0; i < kversions.size(); i++) {
617 def curr = kversions[i]
619 // Keep the newest tag
620 if (i == kversions.size() - 1) {
624 // Prune non-LTS versions
626 for (j = 0; j < lts_kversions.size(); j++) {
627 if (curr.isSameStable(lts_kversions[j])) {
641 // No filtering of kernel versions
642 println('No kernel versions filtering selected.')
646 if (kverrc == "true") {
647 // If the last RC version is newer than the last stable, add it to the build list
648 if (kversionsRC.size() > 0 && kversionsRC.last() > kversions.last()) {
649 kversions.add(kversionsRC.last())
653 println "Building the following kernel versions:"
654 for (k in kversions) {
658 // Debug: Stop build here
659 //throw new InterruptedException()
661 def joburl = HyperlinkNote.encodeTo('/' + job.url, job.fullDisplayName)
664 def ongoingBuild = []
667 def similarJobQueued = 0;
669 // Loop while we have kernel versions remaining or jobs running
670 while ( kversions.size() != 0 || ongoingBuild.size() != 0 ) {
672 if(ongoingBuild.size() < maxConcurrentBuild.toInteger() && kversions.size() != 0) {
673 def kversion = kversions.pop()
675 new StringParameterValue('mversion', mbranch),
676 new StringParameterValue('mgitrepo', mgitrepo),
677 new StringParameterValue('ktag', kversion.toString()),
678 new StringParameterValue('kgitrepo', kgitrepo),
681 // Launch the parametrized build
682 def param_build = job.scheduleBuild2(0, new Cause.UpstreamCause(build), new ParametersAction(job_params))
683 println "triggering ${joburl} for the ${mbranch} branch on kernel ${kversion}"
685 // Add it to the ongoing build queue
686 ongoingBuild.push(param_build)
690 println "Waiting... Queued: " + kversions.size() + " Running: " + ongoingBuild.size()
694 if (e in InterruptedException) {
695 build.setResult(hudson.model.Result.ABORTED)
696 throw new InterruptedException()
702 // Abort job if a newer instance is queued
703 if (!currentJobName.contains("gerrit")) {
704 similarJobQueued = Hudson.instance.queue.items.count{it.task.getFullDisplayName() == currentJobName}
705 if (similarJobQueued > 0) {
706 println "Abort, a newer instance of the job was queued"
707 build.setResult(hudson.model.Result.ABORTED)
708 throw new InterruptedException()
712 def i = ongoingBuild.iterator()
713 while ( i.hasNext() ) {
714 currentBuild = i.next()
715 if ( currentBuild.isCancelled() || currentBuild.isDone() ) {
720 def matrixParent = currentBuild.get()
721 allBuilds.add(matrixParent)
722 def kernelStr = matrixParent.buildVariableResolver.resolve("ktag")
723 println "${matrixParent.fullDisplayName} (${kernelStr}) completed with status ${matrixParent.result}"
725 // Process child runs of matrixBuild
726 def childRuns = matrixParent.getRuns()
727 for ( childRun in childRuns ) {
728 println "\t${childRun.fullDisplayName} (${kernelStr}) completed with status ${childRun.result}"
729 if (childRun.result != Result.SUCCESS) {
730 failedRuns.add(childRun)
739 // Get log of failed runs
740 for (failedRun in failedRuns) {
741 println "---START---"
742 failedRun.writeWholeLogTo(out)
746 println "---Build report---"
747 for (b in allBuilds) {
748 def kernelStr = b.buildVariableResolver.resolve("ktag")
749 println "${b.fullDisplayName} (${kernelStr}) completed with status ${b.result}"
756 // Mark this build failed if any child build has failed
758 build.setResult(hudson.model.Result.FAILURE)