| 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\.2-6\.2\.0-.*_22\.04\.\d+)$/, |
| 632 | ~/^refs\/tags\/(Ubuntu-hwe-6\.5-6\.5\.0-.*_22\.04\.\d+)$/, |
| 633 | ] |
| 634 | break |
| 635 | |
| 636 | case 'focal': |
| 637 | matchStrs = [ |
| 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+)$/, |
| 641 | ] |
| 642 | break |
| 643 | |
| 644 | case 'noble': |
| 645 | matchStrs = [ |
| 646 | ~/^refs\/tags\/(Ubuntu-6\.8\.0-\d{1,3}?\.[\d]+)$/, |
| 647 | ] |
| 648 | break |
| 649 | |
| 650 | default: |
| 651 | println "Unsupported Ubuntu version: ${uversion}" |
| 652 | throw new InterruptedException() |
| 653 | break |
| 654 | } |
| 655 | } else { |
| 656 | // Vanilla |
| 657 | kversionFactory = new VanillaKVersion() |
| 658 | matchStrs = [ |
| 659 | ~/^refs\/tags\/(v[\d\.]+(-rc(\d+))?)$/, |
| 660 | ] |
| 661 | blacklist = [ |
| 662 | 'v3.2.3', |
| 663 | ] |
| 664 | } |
| 665 | |
| 666 | // Parse kernel versions |
| 667 | def kverfloor = "" |
| 668 | try { |
| 669 | kverfloor = kversionFactory.factory(kverfloor_raw) |
| 670 | } catch (EmptyKVersionException e) { |
| 671 | kverfloor = kversionFactory.minKVersion() |
| 672 | } |
| 673 | |
| 674 | def kverceil = "" |
| 675 | try { |
| 676 | kverceil = kversionFactory.factory(kverceil_raw) |
| 677 | } catch (EmptyKVersionException e) { |
| 678 | kverceil = kversionFactory.maxKVersion() |
| 679 | } |
| 680 | |
| 681 | // Build a sorted list of versions to build |
| 682 | for (ref in refs) { |
| 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)) |
| 687 | |
| 688 | if ((v >= kverfloor) && (v < kverceil)) { |
| 689 | if (v.isRC()) { |
| 690 | kversionsRC.add(v) |
| 691 | } else { |
| 692 | kversions.add(v) |
| 693 | } |
| 694 | } |
| 695 | } |
| 696 | } |
| 697 | } |
| 698 | |
| 699 | // The filtering step assumes the version lists are sorted |
| 700 | kversions.sort() |
| 701 | kversionsRC.sort() |
| 702 | |
| 703 | switch (kverfilter) { |
| 704 | case 'stable-head': |
| 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.') |
| 707 | |
| 708 | for (i = 0; i < kversions.size(); i++) { |
| 709 | def curr = kversions[i] |
| 710 | def next = i < kversions.size() - 1 ? kversions[i + 1] : null |
| 711 | |
| 712 | if (next != null) { |
| 713 | if (curr.isSameStable(next)) { |
| 714 | kversions.remove(i) |
| 715 | i-- |
| 716 | } |
| 717 | } |
| 718 | } |
| 719 | break |
| 720 | |
| 721 | case 'lts-head': |
| 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.') |
| 724 | |
| 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 |
| 747 | |
| 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 |
| 752 | |
| 753 | if (next != null) { |
| 754 | if (curr.isSameStable(next)) { |
| 755 | kversions.remove(i) |
| 756 | i-- |
| 757 | } |
| 758 | } |
| 759 | } |
| 760 | |
| 761 | for (i = 0; i < kversions.size(); i++) { |
| 762 | def curr = kversions[i] |
| 763 | |
| 764 | // Keep the newest tag |
| 765 | if (i == kversions.size() - 1) { |
| 766 | break |
| 767 | } |
| 768 | |
| 769 | // Prune non-LTS versions |
| 770 | def keep = false |
| 771 | for (j = 0; j < lts_kversions.size(); j++) { |
| 772 | if (curr.isSameStable(lts_kversions[j])) { |
| 773 | keep = true |
| 774 | break |
| 775 | } |
| 776 | } |
| 777 | |
| 778 | if (!keep) { |
| 779 | kversions.remove(i) |
| 780 | i-- |
| 781 | } |
| 782 | } |
| 783 | break |
| 784 | |
| 785 | default: |
| 786 | // No filtering of kernel versions |
| 787 | println('No kernel versions filtering selected.') |
| 788 | break |
| 789 | } |
| 790 | |
| 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()) |
| 795 | } |
| 796 | } |
| 797 | |
| 798 | println "Building the following kernel versions:" |
| 799 | for (k in kversions) { |
| 800 | println k |
| 801 | } |
| 802 | |
| 803 | // Debug: Stop build here |
| 804 | //throw new InterruptedException() |
| 805 | |
| 806 | def joburl = HyperlinkNote.encodeTo('/' + job.url, job.fullDisplayName) |
| 807 | |
| 808 | def allBuilds = [] |
| 809 | def ongoingBuild = [] |
| 810 | def failedRuns = [] |
| 811 | def isFailed = false |
| 812 | def similarJobQueued = 0; |
| 813 | |
| 814 | // Loop while we have kernel versions remaining or jobs running |
| 815 | while ( kversions.size() != 0 || ongoingBuild.size() != 0 ) { |
| 816 | |
| 817 | if(ongoingBuild.size() < maxConcurrentBuild.toInteger() && kversions.size() != 0) { |
| 818 | def kversion = kversions.pop() |
| 819 | def job_params = [ |
| 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')) |
| 827 | ] |
| 828 | |
| 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}" |
| 832 | |
| 833 | // Add it to the ongoing build queue |
| 834 | ongoingBuild.push(param_build) |
| 835 | |
| 836 | } else { |
| 837 | |
| 838 | println "Waiting... Queued: " + kversions.size() + " Running: " + ongoingBuild.size() |
| 839 | try { |
| 840 | Thread.sleep(10000) |
| 841 | } catch(e) { |
| 842 | if (e in InterruptedException) { |
| 843 | build.setResult(hudson.model.Result.ABORTED) |
| 844 | throw new InterruptedException() |
| 845 | } else { |
| 846 | throw(e) |
| 847 | } |
| 848 | } |
| 849 | |
| 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() |
| 857 | } |
| 858 | } |
| 859 | |
| 860 | def i = ongoingBuild.iterator() |
| 861 | while ( i.hasNext() ) { |
| 862 | currentBuild = i.next() |
| 863 | if ( currentBuild.isCancelled() || currentBuild.isDone() ) { |
| 864 | // Remove from queue |
| 865 | i.remove() |
| 866 | |
| 867 | // Print results |
| 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}" |
| 872 | |
| 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) |
| 879 | isFailed = true |
| 880 | } |
| 881 | } |
| 882 | } |
| 883 | } |
| 884 | } |
| 885 | } |
| 886 | |
| 887 | // Get log of failed runs |
| 888 | for (failedRun in failedRuns) { |
| 889 | println "---START---" |
| 890 | failedRun.writeWholeLogTo(out) |
| 891 | println "---END---" |
| 892 | } |
| 893 | |
| 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}" |
| 898 | // Cleanup builds |
| 899 | try { |
| 900 | b.delete() |
| 901 | } catch (all) {} |
| 902 | } |
| 903 | |
| 904 | // Mark this build failed if any child build has failed |
| 905 | if (isFailed) { |
| 906 | build.setResult(hudson.model.Result.FAILURE) |
| 907 | } |
| 908 | |
| 909 | // EOF |