-
-
Notifications
You must be signed in to change notification settings - Fork 251
/
openjdk_build_pipeline.groovy
1238 lines (1067 loc) · 55.2 KB
/
openjdk_build_pipeline.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import common.IndividualBuildConfig
import common.MetaData
@Library('local-lib@master')
import common.VersionInfo
import groovy.json.*
import java.nio.file.NoSuchFileException
import org.jenkinsci.plugins.workflow.steps.FlowInterruptedException
import java.util.regex.Matcher
/*
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/**
* This file is a template for running a build for a given configuration
* A configuration is for example jdk10u-mac-x64-hotspot.
*
* This file is referenced by the pipeline template create_job_from_template.groovy
*
* A pipeline looks like:
* 1. Check out and build JDK by calling build-farm/make-adopt-build-farm.sh
* 2. Archive artifacts created by build
* 3. Run all tests defined in the configuration
* 4. Sign artifacts if needed and re-archive
*
*/
/*
Extracts the named regex element `groupName` from the `matched` regex matcher and adds it to `map.name`
If it is not present add `0`
*/
class Build {
final IndividualBuildConfig buildConfig
final def context
final def env
final def currentBuild
VersionInfo versionInfo = null
String scmRef = ""
String fullVersionOutput = ""
String configureArguments = ""
String j9Major = ""
String j9Minor = ""
String j9Security = ""
String j9Tags = ""
String vendorName = ""
String buildSource = ""
String crossCompileVersionPath = ""
Map variantVersion = [:]
// Declare timeouts for each critical stage (unit is HOURS)
Map buildTimeouts = [
API_REQUEST_TIMEOUT : 1,
NODE_CLEAN_TIMEOUT : 1,
NODE_CHECKOUT_TIMEOUT : 1,
BUILD_JDK_TIMEOUT : 8,
BUILD_ARCHIVE_TIMEOUT : 3,
AIX_CLEAN_TIMEOUT : 1,
MASTER_CLEAN_TIMEOUT : 1,
DOCKER_CHECKOUT_TIMEOUT : 1,
DOCKER_PULL_TIMEOUT : 2
]
/*
Constructor
*/
Build(IndividualBuildConfig buildConfig, def context, def env, def currentBuild) {
this.buildConfig = buildConfig
this.context = context
this.currentBuild = currentBuild
this.env = env
}
/*
Returns the java version number for this job (e.g. 8, 11, 15, 16)
*/
Integer getJavaVersionNumber() {
def javaToBuild = buildConfig.JAVA_TO_BUILD
// version should be something like "jdk8u" or "jdk" for HEAD
Matcher matcher = javaToBuild =~ /.*?(?<version>\d+).*?/
if (matcher.matches()) {
return Integer.parseInt(matcher.group('version'))
} else if ("jdk".equalsIgnoreCase(javaToBuild.trim())) {
int headVersion
try {
context.timeout(time: buildTimeouts.API_REQUEST_TIMEOUT, unit: "HOURS") {
// Query the Adopt api to get the "tip_version"
def JobHelper = context.library(identifier: 'openjdk-jenkins-helper@master').JobHelper
context.println "Querying Adopt Api for the JDK-Head number (tip_version)..."
def response = JobHelper.getAvailableReleases(context)
headVersion = (int) response.getAt("tip_version")
context.println "Found Java Version Number: ${headVersion}"
}
} catch (FlowInterruptedException e) {
context.println "[ERROR] Adopt API Request timeout (${buildTimeouts.API_REQUEST_TIMEOUT} HOURS) has been reached. Exiting..."
throw new Exception()
}
return headVersion
} else {
context.error("Failed to read java version '${javaToBuild}'")
throw new Exception()
}
}
/*
Calculates which test job we should execute for each requested test type.
The test jobs all follow the same name naming pattern that is defined in the openjdk-tests repository.
E.g. Test_openjdk11_hs_sanity.system_ppc64_aix
*/
def determineTestJobName(testType) {
def variant
def number = getJavaVersionNumber()
switch (buildConfig.VARIANT) {
case "openj9": variant = "j9"; break
case "corretto": variant = "corretto"; break
case "dragonwell": variant = "dragonwell"; break;
default: variant = "hs"
}
def arch = buildConfig.ARCHITECTURE
if (arch == "x64") {
arch = "x86-64"
}
def os = buildConfig.TARGET_OS
def jobName = "Test_openjdk${number}_${variant}_${testType}_${arch}_${os}"
if (buildConfig.ADDITIONAL_FILE_NAME_TAG) {
switch (buildConfig.ADDITIONAL_FILE_NAME_TAG) {
case ~/.*XL.*/: jobName += "_xl"; break
}
}
return "${jobName}"
}
/*
Retrieve the corresponding OpenJDK source code repository branch. This is used the downstream tests to determine what source code branch the tests should run against.
*/
private def getJDKBranch() {
def jdkBranch
if (buildConfig.SCM_REF) {
jdkBranch = buildConfig.SCM_REF
} else {
if (buildConfig.VARIANT == "corretto") {
jdkBranch = 'develop'
} else if (buildConfig.VARIANT == "openj9") {
jdkBranch = 'openj9'
} else if (buildConfig.VARIANT == "hotspot"){
jdkBranch = 'dev'
} else if (buildConfig.VARIANT == "dragonwell") {
jdkBranch = 'master'
} else {
context.error("Unrecognised build variant '${buildConfig.VARIANT}' ")
throw new Exception()
}
}
return jdkBranch
}
/*
Retrieve the corresponding OpenJDK source code repository. This is used the downstream tests to determine what source code the tests should run against.
*/
private def getJDKRepo() {
def jdkRepo
def suffix
def javaNumber = getJavaVersionNumber()
if (buildConfig.VARIANT == "corretto") {
suffix="corretto/corretto-${javaNumber}"
} else if (buildConfig.VARIANT == "openj9") {
suffix = "ibmruntimes/openj9-openjdk-jdk${javaNumber}"
} else if (buildConfig.VARIANT == "hotspot") {
suffix = "adoptopenjdk/openjdk-${buildConfig.JAVA_TO_BUILD}"
} else if (buildConfig.VARIANT == "dragonwell") {
suffix = "alibaba/dragonwell${javaNumber}"
} else {
context.error("Unrecognised build variant '${buildConfig.VARIANT}' ")
throw new Exception()
}
jdkRepo = "https://github.com/${suffix}"
if (buildConfig.BUILD_ARGS.count("--ssh") > 0) {
jdkRepo = "git@github.com:${suffix}"
}
return jdkRepo
}
/*
Run the downstream test jobs based off the configuration passed down from the top level pipeline jobs.
If we try to call a test job that doesn't exist, the pipeline will not fail but it will print out a warning.
If you need more test jobs added, please request so in #testing on Slack.
*/
def runTests() {
def testStages = [:]
List testList = []
def jdkBranch = getJDKBranch()
def jdkRepo = getJDKRepo()
def openj9Branch = (buildConfig.SCM_REF && buildConfig.VARIANT == "openj9") ? buildConfig.SCM_REF : "master"
def additionalTestLabel = buildConfig.ADDITIONAL_TEST_LABEL
if (buildConfig.VARIANT == "corretto") {
testList = buildConfig.TEST_LIST.minus(['sanity.external'])
} else {
testList = buildConfig.TEST_LIST
}
testList.each { testType ->
// For each requested test, i.e 'sanity.openjdk', 'sanity.system', 'sanity.perf', 'sanity.external', call test job
try {
context.println "Running test: ${testType}"
testStages["${testType}"] = {
context.stage("${testType}") {
def keep_test_reportdir = buildConfig.KEEP_TEST_REPORTDIR
if (("${testType}".contains("openjdk")) || ("${testType}".contains("jck"))) {
// Keep test reportdir always for JUnit targets
keep_test_reportdir = "true"
}
// example jobName: Test_openjdk11_hs_sanity.system_ppc64_aix
def jobName = determineTestJobName(testType)
def JobHelper = context.library(identifier: 'openjdk-jenkins-helper@master').JobHelper
// Execute test job
if (JobHelper.jobIsRunnable(jobName as String)) {
context.catchError {
context.build job: jobName,
propagate: false,
parameters: [
context.string(name: 'UPSTREAM_JOB_NUMBER', value: "${env.BUILD_NUMBER}"),
context.string(name: 'UPSTREAM_JOB_NAME', value: "${env.JOB_NAME}"),
context.string(name: 'RELEASE_TAG', value: "${buildConfig.SCM_REF}"),
context.string(name: 'JDK_REPO', value: jdkRepo),
context.string(name: 'JDK_BRANCH', value: jdkBranch),
context.string(name: 'OPENJ9_BRANCH', value: openj9Branch),
context.string(name: 'LABEL_ADDITION', value: additionalTestLabel),
context.string(name: 'KEEP_REPORTDIR', value: "${keep_test_reportdir}"),
context.string(name: 'ACTIVE_NODE_TIMEOUT', value: "${buildConfig.ACTIVE_NODE_TIMEOUT}")]
}
} else {
context.println "[WARNING] Requested test job that does not exist or is disabled: ${jobName}"
}
}
}
} catch (Exception e) {
context.println "Failed execute test: ${e.getLocalizedMessage()}"
}
}
return testStages
}
/*
We use this function at the end of a build to parse a java version string and create a VersionInfo object for deployment in the metadata objects.
E.g. 11.0.9+10-202010192351 would be one example of a matched string.
*/
VersionInfo parseVersionOutput(String consoleOut) {
context.println(consoleOut)
Matcher matcher = (consoleOut =~ /(?ms)^.*OpenJDK Runtime Environment[^\n]*\(build (?<version>[^)]*)\).*$/)
if (matcher.matches()) {
context.println("matched")
String versionOutput = matcher.group('version')
context.println(versionOutput)
return new VersionInfo(context).parse(versionOutput, buildConfig.ADOPT_BUILD_NUMBER)
}
return null
}
/*
Run the Sign downstream job. We run this job on windows and jdk8 hotspot & jdk13 mac builds.
The job code signs and notarizes the binaries so they can run on these operating systems without encountering issues.
*/
def sign(VersionInfo versionInfo) {
// Sign and archive jobs if needed
// TODO: This version info check needs to be updated when the notarization fix gets applied to other versions.
if (
buildConfig.TARGET_OS == "windows" ||
(buildConfig.TARGET_OS == "mac" && versionInfo.major == 8 && buildConfig.VARIANT != "openj9") || (buildConfig.TARGET_OS == "mac" && versionInfo.major == 13)
) {
context.stage("sign") {
def filter = ""
def certificate = ""
def nodeFilter = "${buildConfig.TARGET_OS}"
if (buildConfig.TARGET_OS == "windows") {
filter = "**/OpenJDK*_windows_*.zip"
certificate = "C:\\openjdk\\windows.p12"
nodeFilter = "${nodeFilter}&&build&&win2012"
} else if (buildConfig.TARGET_OS == "mac") {
filter = "**/OpenJDK*_mac_*.tar.gz"
certificate = "\"Developer ID Application: London Jamocha Community CIC\""
nodeFilter = "${nodeFilter}&&macos10.14"
}
def params = [
context.string(name: 'UPSTREAM_JOB_NUMBER', value: "${env.BUILD_NUMBER}"),
context.string(name: 'UPSTREAM_JOB_NAME', value: "${env.JOB_NAME}"),
context.string(name: 'OPERATING_SYSTEM', value: "${buildConfig.TARGET_OS}"),
context.string(name: 'VERSION', value: "${versionInfo.major}"),
context.string(name: 'FILTER', value: "${filter}"),
context.string(name: 'CERTIFICATE', value: "${certificate}"),
['$class': 'LabelParameterValue', name: 'NODE_LABEL', label: "${nodeFilter}"],
]
// Execute sign job
def signJob = context.build job: "build-scripts/release/sign_build",
propagate: true,
parameters: params
// Output notification of downstream failure (the build will fail automatically)
def jobResult = signJob.getResult()
if (jobResult != 'SUCCESS') {
context.println "ERROR: downstream sign_build ${jobResult}.\nSee ${signJob.getAbsoluteUrl()} for details"
}
context.node('master') {
//Copy signed artifact back and archive again
context.sh "rm workspace/target/* || true"
context.copyArtifacts(
projectName: "build-scripts/release/sign_build",
selector: context.specific("${signJob.getNumber()}"),
filter: 'workspace/target/*',
fingerprintArtifacts: true,
target: "workspace/target/",
flatten: true)
context.sh 'for file in $(ls workspace/target/*.tar.gz workspace/target/*.zip); do sha256sum "$file" > $file.sha256.txt ; done'
writeMetadata(versionInfo, false)
context.archiveArtifacts artifacts: "workspace/target/*"
}
}
}
}
/*
Run the Mac installer downstream job.
*/
private void buildMacInstaller(VersionInfo versionData) {
def filter = "**/OpenJDK*_mac_*.tar.gz"
def certificate = "Developer ID Installer: London Jamocha Community CIC"
def nodeFilter = "${buildConfig.TARGET_OS}&&macos10.14&&xcode10"
// Execute installer job
def installerJob = context.build job: "build-scripts/release/create_installer_mac",
propagate: true,
parameters: [
context.string(name: 'UPSTREAM_JOB_NUMBER', value: "${env.BUILD_NUMBER}"),
context.string(name: 'UPSTREAM_JOB_NAME', value: "${env.JOB_NAME}"),
context.string(name: 'FILTER', value: "${filter}"),
context.string(name: 'FULL_VERSION', value: "${versionData.version}"),
context.string(name: 'MAJOR_VERSION', value: "${versionData.major}"),
context.string(name: 'CERTIFICATE', value: "${certificate}"),
['$class': 'LabelParameterValue', name: 'NODE_LABEL', label: "${nodeFilter}"]
]
context.copyArtifacts(
projectName: "build-scripts/release/create_installer_mac",
selector: context.specific("${installerJob.getNumber()}"),
filter: 'workspace/target/*',
fingerprintArtifacts: true,
target: "workspace/target/",
flatten: true)
}
/*
Run the Linux installer downstream job.
*/
private void buildLinuxInstaller(VersionInfo versionData) {
def filter = "**/OpenJDK*_linux_*.tar.gz"
def nodeFilter = "${buildConfig.TARGET_OS}&&fpm"
def buildNumber = versionData.build
String releaseType = "Nightly"
if (buildConfig.RELEASE) {
releaseType = "Release"
}
// Execute installer job
def installerJob = context.build job: "build-scripts/release/create_installer_linux",
propagate: true,
parameters: [
context.string(name: 'UPSTREAM_JOB_NUMBER', value: "${env.BUILD_NUMBER}"),
context.string(name: 'UPSTREAM_JOB_NAME', value: "${env.JOB_NAME}"),
context.string(name: 'FILTER', value: "${filter}"),
context.string(name: 'RELEASE_TYPE', value: "${releaseType}"),
context.string(name: 'VERSION', value: "${versionData.version}"),
context.string(name: 'MAJOR_VERSION', value: "${versionData.major}"),
context.string(name: 'ARCHITECTURE', value: "${buildConfig.ARCHITECTURE}"),
['$class': 'LabelParameterValue', name: 'NODE_LABEL', label: "${nodeFilter}"]
]
}
/*
Run the Windows installer downstream jobs.
We run two jobs if we have a JRE (see https://github.com/AdoptOpenJDK/openjdk-build/issues/1751).
*/
private void buildWindowsInstaller(VersionInfo versionData) {
def filter = "**/OpenJDK*jdk_*_windows*.zip"
def certificate = "C:\\openjdk\\windows.p12"
def buildNumber = versionData.build
if (versionData.major == 8) {
buildNumber = String.format("%02d", versionData.build)
}
def INSTALLER_ARCH = "${buildConfig.ARCHITECTURE}"
// Wix toolset requires aarch64 builds to be called arm64
if (buildConfig.ARCHITECTURE == "aarch64") {
INSTALLER_ARCH = "arm64"
}
// Get version patch number if one is present
def patch_version = versionData.patch ?: 0
// Execute installer job
def installerJob = context.build job: "build-scripts/release/create_installer_windows",
propagate: true,
parameters: [
context.string(name: 'UPSTREAM_JOB_NUMBER', value: "${env.BUILD_NUMBER}"),
context.string(name: 'UPSTREAM_JOB_NAME', value: "${env.JOB_NAME}"),
context.string(name: 'FILTER', value: "${filter}"),
context.string(name: 'PRODUCT_MAJOR_VERSION', value: "${versionData.major}"),
context.string(name: 'PRODUCT_MINOR_VERSION', value: "${versionData.minor}"),
context.string(name: 'PRODUCT_MAINTENANCE_VERSION', value: "${versionData.security}"),
context.string(name: 'PRODUCT_PATCH_VERSION', value: "${patch_version}"),
context.string(name: 'PRODUCT_BUILD_NUMBER', value: "${buildNumber}"),
context.string(name: 'MSI_PRODUCT_VERSION', value: "${versionData.msi_product_version}"),
context.string(name: 'PRODUCT_CATEGORY', value: "jdk"),
context.string(name: 'JVM', value: "${buildConfig.VARIANT}"),
context.string(name: 'SIGNING_CERTIFICATE', value: "${certificate}"),
context.string(name: 'ARCH', value: "${INSTALLER_ARCH}"),
['$class': 'LabelParameterValue', name: 'NODE_LABEL', label: "${buildConfig.TARGET_OS}&&wix"]
]
context.copyArtifacts(
projectName: "build-scripts/release/create_installer_windows",
selector: context.specific("${installerJob.getNumber()}"),
filter: 'wix/ReleaseDir/*',
fingerprintArtifacts: true,
target: "workspace/target/",
flatten: true)
// Check if JRE exists, if so, build another installer for it
listArchives().each({ file ->
if (file.contains("-jre")) {
context.println("We have a JRE. Running another installer for it...")
def jreinstallerJob = context.build job: "build-scripts/release/create_installer_windows",
propagate: true,
parameters: [
context.string(name: 'UPSTREAM_JOB_NUMBER', value: "${env.BUILD_NUMBER}"),
context.string(name: 'UPSTREAM_JOB_NAME', value: "${env.JOB_NAME}"),
context.string(name: 'FILTER', value: "**/OpenJDK*jre_*_windows*.zip"),
context.string(name: 'PRODUCT_MAJOR_VERSION', value: "${versionData.major}"),
context.string(name: 'PRODUCT_MINOR_VERSION', value: "${versionData.minor}"),
context.string(name: 'PRODUCT_MAINTENANCE_VERSION', value: "${versionData.security}"),
context.string(name: 'PRODUCT_PATCH_VERSION', value: "${patch_version}"),
context.string(name: 'PRODUCT_BUILD_NUMBER', value: "${buildNumber}"),
context.string(name: 'MSI_PRODUCT_VERSION', value: "${versionData.msi_product_version}"),
context.string(name: 'PRODUCT_CATEGORY', value: "jre"),
context.string(name: 'JVM', value: "${buildConfig.VARIANT}"),
context.string(name: 'SIGNING_CERTIFICATE', value: "${certificate}"),
context.string(name: 'ARCH', value: "${INSTALLER_ARCH}"),
['$class': 'LabelParameterValue', name: 'NODE_LABEL', label: "${buildConfig.TARGET_OS}&&wix"]
]
context.copyArtifacts(
projectName: "build-scripts/release/create_installer_windows",
selector: context.specific("${jreinstallerJob.getNumber()}"),
filter: 'wix/ReleaseDir/*',
fingerprintArtifacts: true,
target: "workspace/target/",
flatten: true
)
}
})
}
/*
Build installer master function. This builds the downstream installer jobs on completion of the sign and test jobs.
The installers create our rpm, msi and pkg files that allow for an easier installation of the jdk binaries over a compressed archive.
For Mac, we also clean up pkgs on master node from previous runs, if needed (Ref openjdk-build#2350).
*/
def buildInstaller(VersionInfo versionData) {
if (versionData == null || versionData.major == null) {
context.println "Failed to parse version number, possibly a nightly? Skipping installer steps"
return
}
context.node('master') {
context.stage("installer") {
switch (buildConfig.TARGET_OS) {
case "mac": context.sh 'rm -f workspace/target/*.pkg workspace/target/*.pkg.json workspace/target/*.pkg.sha256.txt; done'; buildMacInstaller(versionData); break
case "linux": buildLinuxInstaller(versionData); break
case "windows": buildWindowsInstaller(versionData); break
default: return; break
}
// Archive the Mac and Windows pkg/msi
// (Linux installer job produces no artifacts, it just uploads rpm/deb to the repositories)
if (buildConfig.TARGET_OS == "mac" || buildConfig.TARGET_OS == "windows") {
try {
context.sh 'for file in $(ls workspace/target/*.tar.gz workspace/target/*.pkg workspace/target/*.msi); do sha256sum "$file" > $file.sha256.txt ; done'
writeMetadata(versionData, false)
context.archiveArtifacts artifacts: "workspace/target/*"
} catch (e) {
context.println("Failed to build ${buildConfig.TARGET_OS} installer ${e}")
currentBuild.result = 'FAILURE'
}
}
}
}
}
/*
Lists and returns any compressed archived contents of the top directory of the build node
*/
List<String> listArchives() {
return context.sh(
script: '''find workspace/target/ | egrep '(.tar.gz|.zip|.msi|.pkg|.deb|.rpm)$' ''',
returnStdout: true,
returnStatus: false
)
.trim()
.split('\n')
.toList()
}
/*
On any writeMetadata other than the first, we simply return a MetaData object from the previous writeout adjusted to the situation.
On the first writeout, we pull in the .txt files created by the build that list the attributes of what we used to build the jdk (e.g. configure args, commit hash, etc)
*/
MetaData formMetadata(VersionInfo version, Boolean initialWrite) {
// We have to setup some attributes for the first run since formMetadata is sometimes initiated from downstream job on master node with no access to the required files
if (initialWrite) {
// Get scmRef
context.println "INFO: FIRST METADATA WRITE OUT! Checking if we have a scm reference in the build config..."
String scmRefPath = "workspace/target/metadata/scmref.txt"
scmRef = buildConfig.SCM_REF
if (scmRef != "") {
// Use the buildConfig scmref if it is set
context.println "SUCCESS: SCM_REF has been set (${buildConfig.SCM_REF})! Using it to build the initial metadata over ${scmRefPath}..."
} else {
// If we don't have a scmref set in config, check if we have a scmref from the build
context.println "INFO: SCM_REF is NOT set. Attempting to read ${scmRefPath}..."
try {
scmRef = context.readFile(scmRefPath).trim()
context.println "SUCCESS: scmref.txt found: ${scmRef}"
} catch (NoSuchFileException e) {
// In rare cases, we will fail to create the scmref.txt file
context.println "WARNING: $scmRefPath was not found. Using build config SCM_REF instead (even if it's empty)..."
}
}
// Get Full Version Output
String versionPath = "workspace/target/metadata/version.txt"
if (buildConfig.BUILD_ARGS.contains('--cross-compile')) {
versionPath = crossCompileVersionPath
}
context.println "INFO: Attempting to read ${versionPath}..."
try {
fullVersionOutput = context.readFile(versionPath)
context.println "SUCCESS: ${versionPath} found"
} catch (NoSuchFileException e) {
context.println "ERROR: ${versionPath} was not found. Exiting..."
throw new Exception()
}
// Get Configure Args
String configurePath = "workspace/target/metadata/configure.txt"
context.println "INFO: Attempting to read ${configurePath}..."
try {
configureArguments = context.readFile(configurePath)
context.println "SUCCESS: configure.txt found"
} catch (NoSuchFileException e) {
context.println "ERROR: ${configurePath} was not found. Exiting..."
throw new Exception()
}
// Get Variant Version for OpenJ9
if (buildConfig.VARIANT == "openj9") {
String j9MajorPath = "workspace/target/metadata/variant_version/major.txt"
String j9MinorPath = "workspace/target/metadata/variant_version/minor.txt"
String j9SecurityPath = "workspace/target/metadata/variant_version/security.txt"
String j9TagsPath = "workspace/target/metadata/variant_version/tags.txt"
context.println "INFO: Build variant openj9 detected..."
context.println "INFO: Attempting to read workspace/target/metadata/variant_version/major.txt..."
try {
j9Major = context.readFile(j9MajorPath)
context.println "SUCCESS: major.txt found"
} catch (NoSuchFileException e) {
context.println "ERROR: ${j9MajorPath} was not found. Exiting..."
throw new Exception()
}
context.println "INFO: Attempting to read workspace/target/metadata/variant_version/minor.txt..."
try {
j9Minor = context.readFile(j9MinorPath)
context.println "SUCCESS: minor.txt found"
} catch (NoSuchFileException e) {
context.println "ERROR: ${j9MinorPath} was not found. Exiting..."
throw new Exception()
}
context.println "INFO: Attempting to read workspace/target/metadata/variant_version/security.txt..."
try {
j9Security = context.readFile(j9SecurityPath)
context.println "SUCCESS: security.txt found"
} catch (NoSuchFileException e) {
context.println "ERROR: ${j9SecurityPath} was not found. Exiting..."
throw new Exception()
}
context.println "INFO: Attempting to read workspace/target/metadata/variant_version/tags.txt..."
try {
j9Tags = context.readFile(j9TagsPath)
context.println "SUCCESS: tags.txt found"
} catch (NoSuchFileException e) {
context.println "ERROR: ${j9TagsPath} was not found. Exiting..."
throw new Exception()
}
variantVersion = [major: j9Major, minor: j9Minor, security: j9Security, tags: j9Tags]
}
// Get Vendor
String vendorPath = "workspace/target/metadata/vendor.txt"
context.println "INFO: Attempting to read ${vendorPath}..."
try {
vendorName = context.readFile(vendorPath)
context.println "SUCCESS: vendor.txt found"
} catch (NoSuchFileException e) {
context.println "ERROR: ${vendorPath} was not found. Exiting..."
throw new Exception()
}
// Get Build Source
String buildSourcePath = "workspace/target/metadata/buildSource.txt"
context.println "INFO: Attempting to read ${buildSourcePath}..."
try {
buildSource = context.readFile(buildSourcePath)
context.println "SUCCESS: buildSource.txt found"
} catch (NoSuchFileException e) {
context.println "ERROR: ${buildSourcePath} was not found. Exiting..."
throw new Exception()
}
}
return new MetaData(
vendorName,
buildConfig.TARGET_OS,
scmRef,
buildSource,
version,
buildConfig.JAVA_TO_BUILD,
buildConfig.VARIANT,
variantVersion,
buildConfig.ARCHITECTURE,
fullVersionOutput,
configureArguments
)
}
/*
Calculates and writes out the metadata to a file.
The metadata defines and summarises a build and the jdk it creates.
The adopt v3 api makes use of it in its endpoints to quickly display information about the jdk binaries that are stored on github.
*/
def writeMetadata(VersionInfo version, Boolean initialWrite) {
/*
example data:
{
"vendor": "AdoptOpenJDK",
"os": "mac",
"arch": "x64",
"variant": "openj9",
"variant_version": {
"major": "0",
"minor": "22",
"security": "0",
"tags": "m2"
},
"version": {
"minor": 0,
"security": 0,
"pre": null,
"adopt_build_number": 0,
"major": 15,
"version": "15+29-202007070926",
"semver": "15.0.0+29.0.202007070926",
"build": 29,
"opt": "202007070926"
},
"scmRef": "<output of git describe OR buildConfig.SCM_REF>",
"buildRef": "<build-repo-name/build-commit-sha>",
"version_data": "jdk15",
"binary_type": "debugimage",
"sha256": "<shasum>",
"full_version_output": <output of java --version>,
"configure_arguments": <output of bash configure>
}
*/
MetaData data = initialWrite ? formMetadata(version, true) : formMetadata(version, false)
Boolean metaWrittenOut = false
listArchives().each({ file ->
def type = "jdk"
if (file.contains("-jre")) {
type = "jre"
} else if (file.contains("-testimage")) {
type = "testimage"
} else if (file.contains("-debugimage")) {
type = "debugimage"
}
String hash = context.sh(script: """\
if [ -x "\$(command -v shasum)" ]; then
(shasum -a 256 | cut -f1 -d' ') <$file
else
sha256sum $file | cut -f1 -d' '
fi
""".stripIndent(), returnStdout: true, returnStatus: false)
hash = hash.replaceAll("\n", "")
data.binary_type = type
data.sha256 = hash
// To save on spam, only print out the metadata the first time
if (!metaWrittenOut && initialWrite) {
context.println "===METADATA OUTPUT==="
context.println JsonOutput.prettyPrint(JsonOutput.toJson(data.asMap()))
context.println "=/=METADATA OUTPUT=/="
metaWrittenOut = true
}
context.writeFile file: "${file}.json", text: JsonOutput.prettyPrint(JsonOutput.toJson(data.asMap()))
})
}
/*
Calculates what the binary filename will be based off of the version, arch, os, variant, timestamp and extension.
It will usually be something like OpenJDK8U-jdk_x64_linux_hotspot_2020-10-19-17-06.tar.gz
*/
def determineFileName() {
String javaToBuild = buildConfig.JAVA_TO_BUILD
String architecture = buildConfig.ARCHITECTURE
String os = buildConfig.TARGET_OS
String variant = buildConfig.VARIANT
String additionalFileNameTag = buildConfig.ADDITIONAL_FILE_NAME_TAG
String overrideFileNameVersion = buildConfig.OVERRIDE_FILE_NAME_VERSION
def extension = "tar.gz"
if (os == "windows") {
extension = "zip"
}
javaToBuild = javaToBuild.toUpperCase()
def fileName = "Open${javaToBuild}-jdk_${architecture}_${os}_${variant}"
if (additionalFileNameTag) {
fileName = "${fileName}_${additionalFileNameTag}"
}
if (overrideFileNameVersion) {
fileName = "${fileName}_${overrideFileNameVersion}"
} else if (buildConfig.PUBLISH_NAME) {
// for java 11 remove jdk- and +. i.e jdk-11.0.3+7 -> 11.0.3_7_openj9-0.14.0
def nameTag = buildConfig.PUBLISH_NAME
.replace("jdk-", "")
.replaceAll("\\+", "_")
// for java 8 remove jdk and - before the build. i.e jdk8u212-b03_openj9-0.14.0 -> 8u212b03_openj9-0.14.0
nameTag = nameTag
.replace("jdk", "")
.replace("-b", "b")
fileName = "${fileName}_${nameTag}"
} else {
def timestamp = new Date().format("yyyy-MM-dd-HH-mm", TimeZone.getTimeZone("UTC"))
fileName = "${fileName}_${timestamp}"
}
fileName = "${fileName}.${extension}"
context.println "Filename will be: $fileName"
return fileName
}
/*
Run the cross comile version reader downstream job.
In short, we archive the build artifacts to expose them to the job and run ./java version, copying the output back to here.
See cross_compiled_version_out.groovy.
*/
def readCrossCompiledVersionString() {
// Archive the artifacts early so we can copy them over to the downstream job
try {
context.timeout(time: buildTimeouts.BUILD_ARCHIVE_TIMEOUT, unit: "HOURS") {
context.archiveArtifacts artifacts: "workspace/target/*"
}
} catch (FlowInterruptedException e) {
context.println "[ERROR] Build archive timeout (${buildTimeouts.BUILD_ARCHIVE_TIMEOUT} HOURS) has been reached. Exiting..."
throw new Exception()
}
// Setup params for downstream job & execute
String shortJobName = env.JOB_NAME.split('/').last()
String copyFileFilter = "${shortJobName}_${env.BUILD_NUMBER}_version.txt"
def nodeFilter = "${buildConfig.TARGET_OS}&&${buildConfig.ARCHITECTURE}"
def filter = ""
if (buildConfig.TARGET_OS == "windows") {
filter = "**\\OpenJDK*-jdk*_windows_*.zip"
} else {
filter = "OpenJDK*-jdk*_${buildConfig.TARGET_OS}_*.tar.gz"
}
def crossCompileVersionOut = context.build job: "build-scripts/utils/cross-compiled-version-out",
propagate: true,
parameters: [
context.string(name: 'UPSTREAM_JOB_NAME', value: "${env.JOB_NAME}"),
context.string(name: 'UPSTREAM_JOB_NUMBER', value: "${env.BUILD_NUMBER}"),
context.string(name: 'JDK_FILE_FILTER', value: "${filter}"),
context.string(name: 'FILENAME', value: "${copyFileFilter}"),
context.string(name: 'NODE', value: "${nodeFilter}"),
context.string(name: 'OS', value: "${buildConfig.TARGET_OS}")
]
context.copyArtifacts(
projectName: "build-scripts/utils/cross-compiled-version-out",
selector: context.specific("${crossCompileVersionOut.getNumber()}"),
filter: "CrossCompiledVersionOuts/${copyFileFilter}",
target: "workspace/target/metadata",
flatten: true
)
// We assign to a variable so it can be used in formMetadata() to find the correct version info
crossCompileVersionPath = "workspace/target/metadata/${copyFileFilter}"
return context.readFile(crossCompileVersionPath)
}
/*
Executed on a build node, the function checks out the repository and executes the build via ./make-adopt-build-farm.sh
Once the build completes, it will calculate its version output, commit the first metadata writeout, and archive the build results.
*/
def buildScripts(cleanWorkspace, filename) {
return context.stage("build") {
if (cleanWorkspace) {
try {
try {
context.timeout(time: buildTimeouts.NODE_CLEAN_TIMEOUT, unit: "HOURS") {
if (buildConfig.TARGET_OS == "windows") {
// Windows machines struggle to clean themselves, see:
// https://github.com/AdoptOpenJDK/openjdk-build/issues/1855
context.sh(script: "rm -rf C:/workspace/openjdk-build/workspace/build/src/build/*/jdk/gensrc")
// https://github.com/AdoptOpenJDK/openjdk-infrastructure/issues/1419
context.sh(script: "rm -rf J:/jenkins/tmp/workspace/build/src/build/*/jdk/gensrc")
// https://github.com/AdoptOpenJDK/openjdk-infrastructure/issues/1662
context.sh(script: "rm -rf E:/jenkins/tmp/workspace/build/src/build/*/jdk/gensrc")
context.cleanWs notFailBuild: true, disableDeferredWipeout: true, deleteDirs: true
} else {
context.cleanWs notFailBuild: true
}
}
} catch (FlowInterruptedException e) {
context.println "[ERROR] Node Clean workspace timeout (${buildTimeouts.NODE_CLEAN_TIMEOUT} HOURS) has been reached. Exiting..."
throw new Exception()
}
} catch (e) {
context.println "[WARNING] Failed to clean workspace: ${e}"
}
}
try {
context.timeout(time: buildTimeouts.NODE_CHECKOUT_TIMEOUT, unit: "HOURS") {
context.checkout context.scm
// Perform a git clean outside of checkout to avoid the Jenkins enforced 10 minute timeout
// https://github.com/AdoptOpenJDK/openjdk-infrastructure/issues/1553
context.sh(script: "git clean -fdx")
}
} catch (FlowInterruptedException e) {
context.println "[ERROR] Node checkout workspace timeout (${buildTimeouts.NODE_CHECKOUT_TIMEOUT} HOURS) has been reached. Exiting..."
throw new Exception()
}
try {
// Convert IndividualBuildConfig to jenkins env variables
List<String> envVars = buildConfig.toEnvVars()
envVars.add("FILENAME=${filename}" as String)
// Execute build
context.withEnv(envVars) {
try {
context.timeout(time: buildTimeouts.BUILD_JDK_TIMEOUT, unit: "HOURS") {
context.sh(script: "./build-farm/make-adopt-build-farm.sh")
}
} catch (FlowInterruptedException e) {
context.println "[ERROR] Build JDK timeout (${buildTimeouts.BUILD_JDK_TIMEOUT} HOURS) has been reached. Exiting..."
throw new Exception()
}
// Run a downstream job on riscv machine that returns the java version
// otherwise, just read the version.txt
String versionOut
if (buildConfig.BUILD_ARGS.contains('--cross-compile')) {
context.println "[WARNING] Don't read faked version.txt on cross compiled build! Archiving early and running downstream job to retrieve java version..."
versionOut = readCrossCompiledVersionString()
} else {
versionOut = context.readFile("workspace/target/metadata/version.txt")
}
versionInfo = parseVersionOutput(versionOut)
}
writeMetadata(versionInfo, true)
try {
context.timeout(time: buildTimeouts.BUILD_ARCHIVE_TIMEOUT, unit: "HOURS") {
// We have already archived cross compiled artifacts, so only archive the metadata files
if (buildConfig.BUILD_ARGS.contains('--cross-compile')) {
context.println "[INFO] Archiving JSON Files..."
context.archiveArtifacts artifacts: "workspace/target/*.json"
} else {
context.archiveArtifacts artifacts: "workspace/target/*"
}
}
} catch (FlowInterruptedException e) {
context.println "[ERROR] Build archive timeout (${buildTimeouts.BUILD_ARCHIVE_TIMEOUT} HOURS) has been reached. Exiting..."
throw new Exception()
}
} finally {
// post-build workspace clean:
// AIX due to limited ram drive space
// s390x due to limited available disk space on Marist nodes
if (buildConfig.TARGET_OS == "aix" || buildConfig.ARCHITECTURE == "s390x") {
try {
context.timeout(time: buildTimeouts.AIX_CLEAN_TIMEOUT, unit: "HOURS") {
context.cleanWs notFailBuild: true