forked from adoptium/ci-jenkins-pipelines
-
Notifications
You must be signed in to change notification settings - Fork 0
/
openjdk_build_pipeline.groovy
2289 lines (2077 loc) · 119 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
/*
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.
*/
/* groovylint-disable MethodCount */
import common.IndividualBuildConfig
import common.MetaData
import common.VersionInfo
import common.RepoHandler
import groovy.json.*
import java.nio.file.NoSuchFileException
import org.jenkinsci.plugins.workflow.steps.FlowInterruptedException
import java.util.regex.Matcher
/**
* This file is a template for running a build for a given configuration
* A configuration is for example jdk10u-mac-x64-temurin.
*
* 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 Map USER_REMOTE_CONFIGS
final Map DEFAULTS_JSON
final Map ADOPT_DEFAULTS_JSON
final context
final env
final currentBuild
VersionInfo versionInfo = null
String scmRef = ''
String fullVersionOutput = ''
String makejdkArgs = ''
String configureArguments = ''
String makeCommandArgs = ''
String j9Major = ''
String j9Minor = ''
String j9Security = ''
String j9Tags = ''
String vendorName = ''
String buildSource = ''
String openjdkSource = ''
String openjdk_built_config = ''
String dockerImageDigest = ''
Map<String,String> dependency_version = new HashMap<String,String>()
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,
CONTROLLER_CLEAN_TIMEOUT : 1,
DOCKER_CHECKOUT_TIMEOUT : 1,
DOCKER_PULL_TIMEOUT : 2,
ARCHIVE_ARTIFACTS_TIMEOUT : 6
]
/*
Constructor
*/
Build(
IndividualBuildConfig buildConfig,
Map USER_REMOTE_CONFIGS,
Map DEFAULTS_JSON,
Map ADOPT_DEFAULTS_JSON,
def context,
def env,
def currentBuild
) {
this.buildConfig = buildConfig
this.USER_REMOTE_CONFIGS = USER_REMOTE_CONFIGS
this.DEFAULTS_JSON = DEFAULTS_JSON
this.ADOPT_DEFAULTS_JSON = ADOPT_DEFAULTS_JSON
this.context = context
this.currentBuild = currentBuild
this.env = env
}
/*
Returns the java version number for this job (e.g. 8, 11, 17, ...)
*/
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"
String helperRef = buildConfig.HELPER_REF ?: DEFAULTS_JSON['repository']['helper_ref']
def JobHelper = context.library(identifier: "openjdk-jenkins-helper@${helperRef}").JobHelper
context.println 'Querying Adopt Api for the JDK-Head number (tip_version)...'
def response = JobHelper.getAvailableReleases(context)
headVersion = (int) response[('tip_version')]
context.println "Found Java Version Number: ${headVersion}"
}
} catch (FlowInterruptedException e) {
throw new Exception("[ERROR] Adopt API Request timeout (${buildTimeouts.API_REQUEST_TIMEOUT} HOURS) has been reached. Exiting...")
}
return headVersion
} else {
throw new Exception("Failed to read java version '${javaToBuild}'")
}
}
/*
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 aqa-tests repository.
E.g. Test_openjdk11_hs_sanity.system_ppc64_aix
*/
def getSmokeTestJobParams() {
def jobParams = getCommonTestJobParams()
jobParams.put('LEVELS', 'extended')
jobParams.put('GROUPS', 'functional')
jobParams.put('TEST_JOB_NAME', "${env.JOB_NAME}_SmokeTests")
jobParams.put('BUILD_LIST', 'functional/buildAndPackage')
def vendorTestRepos = ((String)ADOPT_DEFAULTS_JSON['repository']['build_url']) - ('.git')
def vendorTestDirs = ADOPT_DEFAULTS_JSON['repository']['test_dirs']
def vendorTestBranches = ADOPT_DEFAULTS_JSON['repository']['build_branch']
jobParams.put('VENDOR_TEST_REPOS', vendorTestRepos)
jobParams.put('VENDOR_TEST_DIRS', vendorTestDirs)
jobParams.put('VENDOR_TEST_BRANCHES', vendorTestBranches)
return jobParams
}
def getAQATestJobParams(testType) {
def jobParams = getCommonTestJobParams()
def (level, group) = testType.tokenize('.')
jobParams.put('LEVELS', level)
jobParams.put('GROUPS', group)
def variant
switch (buildConfig.VARIANT) {
case 'openj9': variant = 'j9'; break
case 'corretto': variant = 'corretto'; break
case 'dragonwell': variant = 'dragonwell'; break;
case 'fast_startup': variant = 'fast_startup'; break;
case 'bisheng': variant = 'bisheng'; break;
default: variant = 'hs'
}
def jobName = "Test_openjdk${jobParams['JDK_VERSIONS']}_${variant}_${testType}_${jobParams['ARCH_OS_LIST']}"
jobParams.put('TEST_JOB_NAME', jobName)
return jobParams
}
def getCommonTestJobParams() {
def jobParams = [:]
String jdk_Version = getJavaVersionNumber() as String
jobParams.put('JDK_VERSIONS', jdk_Version)
if (buildConfig.VARIANT == 'temurin') {
jobParams.put('JDK_IMPL', 'hotspot')
} else {
jobParams.put('JDK_IMPL', buildConfig.VARIANT)
}
def arch = buildConfig.ARCHITECTURE
if (arch == 'x64') {
arch = 'x86-64'
}
// Default to a 25 hours for all test jobs
jobParams.put('TIME_LIMIT', '25')
def arch_os = "${arch}_${buildConfig.TARGET_OS}"
jobParams.put('ARCH_OS_LIST', arch_os)
jobParams.put('LIGHT_WEIGHT_CHECKOUT', false)
return jobParams
}
/*
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 getJDKBranch() {
def jdkBranch
if (buildConfig.SCM_REF) {
// We need to override the SCM ref on jdk8 arm builds change aarch64-shenandoah-jdk8u282-b08 to jdk8u282-b08
if (buildConfig.JAVA_TO_BUILD == 'jdk8u' && buildConfig.VARIANT == 'temurin' && (buildConfig.ARCHITECTURE == 'aarch64' || buildConfig.ARCHITECTURE == 'arm')) {
jdkBranch = buildConfig.OVERRIDE_FILE_NAME_VERSION
} else {
jdkBranch = buildConfig.SCM_REF
}
} else {
if (buildConfig.VARIANT == 'corretto') {
jdkBranch = 'develop'
} else if (buildConfig.VARIANT == 'openj9') {
jdkBranch = 'openj9'
} else if (buildConfig.VARIANT == 'hotspot') {
jdkBranch = 'master'
} else if (buildConfig.VARIANT == 'temurin') {
// jdk(head) now contains version branched stabilisation branches, eg.dev_jdk23
if (getJavaVersionNumber() >= 23 && !buildConfig.JAVA_TO_BUILD.endsWith('u') && buildConfig.JAVA_TO_BUILD != "jdk") {
jdkBranch = 'dev_'+buildConfig.JAVA_TO_BUILD
} else {
jdkBranch = 'dev'
}
} else if (buildConfig.VARIANT == 'dragonwell') {
jdkBranch = 'master'
} else if (buildConfig.VARIANT == 'fast_startup') {
jdkBranch = 'master'
} else if (buildConfig.VARIANT == 'bisheng') {
jdkBranch = 'master'
} else {
throw new Exception("Unrecognised build variant: ${buildConfig.VARIANT} ")
}
}
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 getJDKRepo() {
def jdkRepo
def suffix
def javaNumber = getJavaVersionNumber()
switch(buildConfig.VARIANT) {
case 'corretto':
suffix = "corretto/corretto-${javaNumber}"
break
case 'openj9':
def openj9JavaToBuild = buildConfig.JAVA_TO_BUILD
if (openj9JavaToBuild.endsWith('u')) {
// OpenJ9 extensions repo does not use the "u" suffix
openj9JavaToBuild = openj9JavaToBuild.substring(0, openj9JavaToBuild.length() - 1)
}
suffix = "ibmruntimes/openj9-openjdk-${openj9JavaToBuild}"
break
case 'temurin':
if (buildConfig.ARCHITECTURE == 'arm' && buildConfig.JAVA_TO_BUILD == 'jdk8u') {
suffix = 'adoptium/aarch32-jdk8u'
} else if (buildConfig.TARGET_OS == 'alpine-linux' && buildConfig.JAVA_TO_BUILD == 'jdk8u') {
suffix = 'adoptium/alpine-jdk8u'
} else if (buildConfig.ARCHITECTURE == 'riscv64' && buildConfig.JAVA_TO_BUILD == 'jdk11u') {
suffix = 'adoptium/riscv-port-jdk11u'
} else {
// jdk(head) repo now contains the version branched stabilisation branches, eg.dev_jdk23
if (javaNumber >= 23 && !buildConfig.JAVA_TO_BUILD.endsWith('u')) {
suffix = "adoptium/jdk"
} else {
suffix = "adoptium/${buildConfig.JAVA_TO_BUILD}"
}
}
break
case 'hotspot':
if (buildConfig.ARCHITECTURE == "riscv64"
&& (buildConfig.JAVA_TO_BUILD == "jdk8u"
|| buildConfig.JAVA_TO_BUILD == "jdk11u")) {
suffix = "openjdk/riscv-port-${buildConfig.JAVA_TO_BUILD}";
} else {
// jdk(head) repo now contains the version branched stabilisation branches, eg.jdk23
if (javaNumber >= 23 && !buildConfig.JAVA_TO_BUILD.endsWith('u')) {
suffix = "openjdk/jdk"
} else {
suffix = "openjdk/${buildConfig.JAVA_TO_BUILD}"
}
}
break
case 'dragonwell':
suffix = "alibaba/dragonwell${javaNumber}"
break
case 'fast_startup':
suffix = 'adoptium/jdk11u-fast-startup-incubator'
break
case 'bisheng':
suffix = "openeuler-mirror/bishengjdk-${javaNumber}"
break
default:
throw new Exception("Unrecognised build variant: ${buildConfig.VARIANT} ")
}
jdkRepo = "https://github.com/${suffix}"
if (buildConfig.BUILD_ARGS.count('--ssh') > 0) {
jdkRepo = "[email protected]:${suffix}"
}
return jdkRepo
}
/*
If the given result is not SUCCESS then set the current stage result and build result accordingly
*/
def setStageResult(String stage, String result) {
if (result != "SUCCESS") {
// Use catchError to issue error message and set build & stage result
context.catchError(buildResult: result, stageResult: result) {
context.error("${stage} not successful, setting stage result to: "+result)
}
} else {
context.println "${stage} result was SUCCESS"
}
}
/*
Run smoke tests, which should block the running of downstream test jobs if there are failures.
If a test job that doesn't exist, it will be created dynamically.
*/
def runSmokeTests() {
def additionalTestLabel = buildConfig.ADDITIONAL_TEST_LABEL
def useAdoptShellScripts = Boolean.valueOf(buildConfig.USE_ADOPT_SHELL_SCRIPTS)
def vendorTestBranches = useAdoptShellScripts ? ADOPT_DEFAULTS_JSON['repository']['build_branch'] : DEFAULTS_JSON['repository']['build_branch']
def vendorTestRepos = useAdoptShellScripts ? ADOPT_DEFAULTS_JSON['repository']['build_url'] : DEFAULTS_JSON['repository']['build_url']
vendorTestRepos = vendorTestRepos - ('.git')
// Use BUILD_REF override if specified
vendorTestBranches = buildConfig.BUILD_REF ?: vendorTestBranches
try {
context.println 'Running smoke test'
context.stage('smoke test') {
def jobParams = getSmokeTestJobParams()
def jobName = jobParams.TEST_JOB_NAME
String helperRef = buildConfig.HELPER_REF ?: DEFAULTS_JSON['repository']['helper_ref']
def JobHelper = context.library(identifier: "openjdk-jenkins-helper@${helperRef}").JobHelper
if (!JobHelper.jobIsRunnable(jobName as String)) {
context.node('worker') {
context.sh('curl -Os https://raw.githubusercontent.com/adoptium/aqa-tests/master/buildenv/jenkins/testJobTemplate')
def templatePath = 'testJobTemplate'
context.println "Smoke test job doesn't exist, create test job: ${jobName}"
context.jobDsl targets: templatePath, ignoreExisting: false, additionalParameters: jobParams
}
}
def testJob = context.build job: jobName,
propagate: false,
parameters: [
context.string(name: 'SDK_RESOURCE', value: 'upstream'),
context.string(name: 'UPSTREAM_JOB_NUMBER', value: "${env.BUILD_NUMBER}"),
context.string(name: 'UPSTREAM_JOB_NAME', value: "${env.JOB_NAME}"),
context.string(name: 'JDK_VERSION', value: "${jobParams.JDK_VERSIONS}"),
context.string(name: 'LABEL_ADDITION', value: additionalTestLabel),
context.booleanParam(name: 'KEEP_REPORTDIR', value: buildConfig.KEEP_TEST_REPORTDIR),
context.string(name: 'ACTIVE_NODE_TIMEOUT', value: "${buildConfig.ACTIVE_NODE_TIMEOUT}"),
context.booleanParam(name: 'DYNAMIC_COMPILE', value: true),
context.string(name: 'VENDOR_TEST_REPOS', value: vendorTestRepos),
context.string(name: 'VENDOR_TEST_BRANCHES', value: vendorTestBranches),
context.string(name: 'TIME_LIMIT', value: '1')
]
currentBuild.result = testJob.getResult()
setStageResult("smoke test", testJob.getResult())
return testJob.getResult()
}
} catch (Exception e) {
context.println "Failed to execute test: ${e.message}"
throw new Exception('[ERROR] Smoke Tests failed indicating a problem with the build artifact. No further tests will run until Smoke test failures are fixed. ')
}
}
/*
Run the downstream test jobs based off the configuration passed down from the top level pipeline jobs.
If a test job doesn't exist, it will be created dynamically.
*/
def runAQATests() {
def testStages = [:]
def jdkBranch = getJDKBranch()
def jdkRepo = getJDKRepo()
def openj9Branch = (buildConfig.SCM_REF && buildConfig.VARIANT == 'openj9') ? buildConfig.SCM_REF : 'master'
def vendorTestRepos = ''
def vendorTestBranches = ''
def vendorTestDirs = ''
List testList = buildConfig.TEST_LIST
def enableTestDynamicParallel = Boolean.valueOf(buildConfig.ENABLE_TESTDYNAMICPARALLEL)
def aqaBranch = 'master'
def useTestEnvProperties = false
if (buildConfig.SCM_REF && buildConfig.AQA_REF) {
aqaBranch = buildConfig.AQA_REF
useTestEnvProperties = true
}
def aqaAutoGen = buildConfig.AQA_AUTO_GEN ?: false
def parallel = 'None'
def numMachinesPerTest = ''
def testTime = ''
// Enable time based parallel. Set expected completion time to 120 mins
if (enableTestDynamicParallel) {
testTime = '120'
parallel = 'Dynamic'
}
testList.each { testType ->
// For each requested test, i.e 'sanity.openjdk', 'sanity.system', 'sanity.perf', 'sanity.external', call test job
try {
testStages["${testType}"] = {
context.println "Running test: ${testType}"
context.stage("${testType}") {
def keep_test_reportdir = buildConfig.KEEP_TEST_REPORTDIR
def rerunIterations = '1'
if ("${testType}".contains('dev') || "${testType}".contains('external')) {
rerunIterations = '0'
}
if (("${testType}".contains('openjdk')) || ("${testType}".contains('jck')) || (testType == 'dev.functional')) {
// Keep test reportdir always for JUnit targets
keep_test_reportdir = true
}
def DYNAMIC_COMPILE = false
if (("${testType}".contains('functional')) || ("${testType}".contains('external'))) {
DYNAMIC_COMPILE = true
}
def additionalTestLabel = buildConfig.ADDITIONAL_TEST_LABEL
if (testType == 'dev.openjdk' || testType == 'special.system') {
context.println "${testType} need extra label sw.tool.docker"
if (additionalTestLabel == '') {
additionalTestLabel = 'sw.tool.docker'
} else {
additionalTestLabel += '&&sw.tool.docker'
}
}
if (testType == 'special.system' || testType == 'dev.system') {
def useAdoptShellScripts = Boolean.valueOf(buildConfig.USE_ADOPT_SHELL_SCRIPTS)
vendorTestBranches = useAdoptShellScripts ? ADOPT_DEFAULTS_JSON['repository']['build_branch'] : DEFAULTS_JSON['repository']['build_branch']
vendorTestRepos = useAdoptShellScripts ? ADOPT_DEFAULTS_JSON['repository']['build_url'] : DEFAULTS_JSON['repository']['build_url']
vendorTestRepos = vendorTestRepos - ('.git')
vendorTestDirs = '/test/system'
// Use BUILD_REF override if specified
vendorTestBranches = buildConfig.BUILD_REF ?: vendorTestBranches
}
def jobParams = getAQATestJobParams(testType)
def jobName = jobParams.TEST_JOB_NAME
String helperRef = buildConfig.HELPER_REF ?: DEFAULTS_JSON['repository']['helper_ref']
def JobHelper = context.library(identifier: "openjdk-jenkins-helper@${helperRef}").JobHelper
// Create test job if AQA_AUTO_GEN is set to true, the job doesn't exist or is not runnable
if (aqaAutoGen || !JobHelper.jobIsRunnable(jobName as String)) {
// use Test_Job_Auto_Gen if it is runnable. Otherwise, use testJobTemplate from aqa-tests repo
if (JobHelper.jobIsRunnable('Test_Job_Auto_Gen')) {
def updatedParams = []
// loop through all the params and set string and boolean accordingly
jobParams.each { param ->
def value = param.value.toString()
if (value == 'true' || value == 'false') {
updatedParams << context.booleanParam(name: param.key, value: value.toBoolean())
} else {
updatedParams << context.string(name: param.key, value: value)
}
}
context.println "Use Test_Job_Auto_Gen to generate AQA test job with parameters: ${updatedParams}"
context.catchError {
context.build job: 'Test_Job_Auto_Gen', propagate: false, parameters: updatedParams
}
} else {
context.node('worker') {
context.sh('curl -Os https://raw.githubusercontent.com/adoptium/aqa-tests/master/buildenv/jenkins/testJobTemplate')
def templatePath = 'testJobTemplate'
if (!JobHelper.jobIsRunnable(jobName as String)) {
context.println "AQA test job: ${jobName} doesn't exist, use testJobTemplate to generate job : ${jobName}"
} else {
context.println "Use testJobTemplate to regenerate job: ${jobName}, note: default job parameters may change."
}
context.jobDsl targets: templatePath, ignoreExisting: false, additionalParameters: jobParams
}
}
}
def testJobParams = [
context.string(name: 'UPSTREAM_JOB_NUMBER', value: "${env.BUILD_NUMBER}"),
context.string(name: 'UPSTREAM_JOB_NAME', value: "${env.JOB_NAME}"),
context.string(name: 'SDK_RESOURCE', value: 'upstream'),
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.booleanParam(name: 'KEEP_REPORTDIR', value: keep_test_reportdir),
context.string(name: 'PARALLEL', value: parallel),
context.string(name: 'NUM_MACHINES', value: "${numMachinesPerTest}"),
context.string(name: 'TEST_TIME', value: testTime),
context.booleanParam(name: 'USE_TESTENV_PROPERTIES', value: useTestEnvProperties),
context.booleanParam(name: 'GENERATE_JOBS', value: aqaAutoGen),
context.string(name: 'ADOPTOPENJDK_BRANCH', value: aqaBranch),
context.string(name: 'ACTIVE_NODE_TIMEOUT', value: "${buildConfig.ACTIVE_NODE_TIMEOUT}"),
context.booleanParam(name: 'DYNAMIC_COMPILE', value: DYNAMIC_COMPILE),
context.string(name: 'VENDOR_TEST_REPOS', value: vendorTestRepos),
context.string(name: 'VENDOR_TEST_BRANCHES', value: vendorTestBranches),
context.string(name: 'VENDOR_TEST_DIRS', value: vendorTestDirs),
context.string(name: 'RERUN_ITERATIONS', value: "${rerunIterations}")
]
// If TIME_LIMIT is set, override target job default TIME_LIMIT value.
if (jobParams.any{mapEntry -> mapEntry.key.equals("TIME_LIMIT")}) {
testJobParams.add(context.string(name: 'TIME_LIMIT', value: jobParams["TIME_LIMIT"]))
}
def testJob = context.build job: jobName,
propagate: false,
parameters: testJobParams,
wait: true
currentBuild.result = testJob.getResult()
setStageResult("${testType}", testJob.getResult())
context.node('worker') {
//Copy Taps files from downstream test jobs if files available.
context.sh 'rm -f workspace/target/AQAvitTaps/*.tap'
try {
context.timeout(time: 2, unit: 'HOURS') {
context.copyArtifacts(
projectName:jobName,
selector:context.specific("${testJob.getNumber()}"),
filter: "**/${jobName}*.tap",
target: 'workspace/target/AQAvitTaps/',
fingerprintArtifacts: true,
flatten: true
)
}
} catch (Exception e) {
context.echo "Cannot run copyArtifacts from job ${jobName}. Exception: ${e.message}. Skipping copyArtifacts..."
}
context.archiveArtifacts allowEmptyArchive: true, artifacts: 'workspace/target/AQAvitTaps/*.tap', fingerprint: true
}
}
}
} catch (Exception e) {
context.println "Failed to execute test: ${e.message}"
currentBuild.result = 'FAILURE'
}
}
return testStages
}
// Temurin remote jck trigger
def remoteTriggerJckTests(String platform, String jdkFileName) {
def jdkVersion = getJavaVersionNumber()
// We just need the JDK for Jck tests
def sdkUrl = "${env.BUILD_URL}/artifact/workspace/target/${jdkFileName}"
context.echo "sdkUrl is ${sdkUrl}"
def remoteTargets = [:]
def additionalTestLabel = buildConfig.ADDITIONAL_TEST_LABEL
def setupJCKRun = false
if (buildConfig.SCM_REF && buildConfig.AQA_REF && sdkUrl.contains("release")) {
setupJCKRun = true
}
// Determine from the platform the Jck jtx exclude platform
def excludePlat
def excludeRoot = "/home"
if (platform.contains("aix")) {
excludePlat = "aix"
} else if (platform.contains("mac")) {
excludePlat = "mac"
excludeRoot = "/Users"
} else if (platform.contains("windows")) {
excludePlat = "windows"
excludeRoot = "c:/Users"
} else if (platform.contains("solaris")) {
excludePlat = "solaris"
excludeRoot = "/export/home"
} else {
excludePlat = "linux"
}
def appOptions="customJtx=${excludeRoot}/jenkins/jck_run/jdk${jdkVersion}/${excludePlat}/temurin.jtx"
if (configureArguments.contains('--enable-headless-only=yes')) {
// Headless platforms have no auto-manuals, so do not exclude any tests
appOptions=""
}
def targets = ['serial': 'sanity.jck,extended.jck,special.jck']
if ("${platform}" == 'x86-64_linux' || "${platform}" == 'x86-64_windows' || "${platform}" == 'x86-64_mac') {
// Primary platforms run extended.jck in Parallel
targets['serial'] = 'sanity.jck,special.jck'
targets['parallel'] = 'extended.jck'
}
/*
Here we limit the win32 testing to the burstable nodes (a subset of the available windows nodes).
This prevents win32 tests from occupying all the Windows nodes before we can test core platform win64.
*/
if ("${platform}" == 'x86-32_windows') {
context.println "Windows 32bit JCK tests need the extra label hw.cpu.burstable"
if (additionalTestLabel == '') {
additionalTestLabel = 'hw.cpu.burstable'
} else {
additionalTestLabel += '&&hw.cpu.burstable'
}
}
targets.each { targetMode, targetTests ->
try {
context.println "Remote trigger: ${targetTests}"
remoteTargets["${targetTests}"] = {
def displayName = "jdk${jdkVersion} : ${buildConfig.SCM_REF} : ${platform} : ${targetTests}"
def parallel = 'None'
def num_machines = '1'
if ("${targetMode}" == 'parallel') {
parallel = 'Dynamic'
num_machines = '2'
}
context.catchError {
context.triggerRemoteJob abortTriggeredJob: true,
blockBuildUntilComplete: false,
job: 'AQA_Test_Pipeline',
parameters: context.MapParameters(parameters: [context.MapParameter(name: 'SDK_RESOURCE', value: 'customized'),
context.MapParameter(name: 'TARGETS', value: "${targetTests}"),
context.MapParameter(name: 'CUSTOMIZED_SDK_URL', value: "${sdkUrl}"),
context.MapParameter(name: 'JDK_VERSIONS', value: "${jdkVersion}"),
context.MapParameter(name: 'PARALLEL', value: parallel),
context.MapParameter(name: 'NUM_MACHINES', value: "${num_machines}"),
context.MapParameter(name: 'PLATFORMS', value: "${platform}"),
context.MapParameter(name: 'PIPELINE_DISPLAY_NAME', value: "${displayName}"),
context.MapParameter(name: 'APPLICATION_OPTIONS', value: "${appOptions}"),
context.MapParameter(name: 'LABEL_ADDITION', value: additionalTestLabel),
context.MapParameter(name: 'cause', value: "Remote triggered by job ${env.BUILD_URL}"), // Label is lowercase on purpose to map to the Jenkins target reporting system
context.MapParameter(name: 'SETUP_JCK_RUN', value: "${setupJCKRun}")]),
remoteJenkinsName: 'temurin-compliance',
shouldNotFailBuild: true,
token: 'RemoteTrigger',
useCrumbCache: true,
useJobInfoCache: true
}
}
} catch (Exception e) {
context.println "Failed to remote trigger jck tests: ${e.message}"
}
}
return remoteTargets
}
def compareReproducibleBuild(String nonDockerNodeName) {
// Currently only enable for jdk17, linux_x64, temurin, nightly, which shouldn't affect current build
// Move out of normal jdk** folder as it won't be regenerated automatically right now
def buildJobName = "${env.JOB_NAME}"
buildJobName = buildJobName.substring(buildJobName.lastIndexOf('/')+1)
def comparedJobName = "${buildJobName}_reproduce_compare"
if (!Boolean.valueOf(buildConfig.RELEASE)) {
// For now set the build as independent, no need to wait for result as the build takes time
String helperRef = buildConfig.HELPER_REF ?: DEFAULTS_JSON['repository']['helper_ref']
def JobHelper = context.library(identifier: "openjdk-jenkins-helper@${helperRef}").JobHelper
if (!JobHelper.jobIsRunnable(comparedJobName as String)) {
context.node('worker') {
context.println "Reproduce_compare job doesn't exist, create reproduce_compare job: ${comparedJobName}"
context.jobDsl scriptText: """
pipelineJob("${comparedJobName}") {
description(\'<h1>THIS IS AN AUTOMATICALLY GENERATED JOB. PLEASE DO NOT MODIFY, IT WILL BE OVERWRITTEN.</h1>\')
definition {
parameters {
stringParam("COMPARED_JOB_NUMBER", "", "Compared nightly build job number.")
stringParam("COMPARED_JOB_NAME", "", "Compared nightly build job name")
stringParam("COMPARED_AGENT", "", "Compared nightly build job agent.")
stringParam("COMPARED_JOB_PARAMS", "", "Compared nightly build job parameters")
}
cpsScm {
scm {
git {
remote {
url("https://github.com/adoptium/ci-jenkins-pipelines.git")
}
branch("*/master")
}
scriptPath("tools/reproduce_comparison/Jenkinsfile")
lightweight(true)
}
}
logRotator {
numToKeep(30)
artifactNumToKeep(10)
daysToKeep(60)
artifactDaysToKeep(10)
}
}
}
""" , ignoreExisting: false
}
}
context.stage('Reproduce Compare') {
def buildParams = context.params.toString()
// passing buildParams multiline parameter to downstream job, double check the available method
context.build job: comparedJobName,
propagate: false,
parameters: [
context.string(name: 'COMPARED_JOB_NUMBER', value: "${env.BUILD_NUMBER}"),
context.string(name: 'COMPARED_JOB_NAME', value: "${env.JOB_NAME}"),
context.string(name: 'COMPARED_AGENT', value: nonDockerNodeName),
context.string(name: 'COMPARED_JOB_PARAMS', value: buildParams)
],
wait: false
}
}
}
/*
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.
The regex would match both OpenJDK Runtime Environment and Java(TM) SE Runtime Environment.
*/
VersionInfo parseVersionOutput(String consoleOut) {
context.println(consoleOut)
Matcher matcher = (consoleOut =~ /(?ms)^.*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
if (
buildConfig.TARGET_OS == 'windows' || (buildConfig.TARGET_OS == 'mac')
) {
context.stage('sign') {
def filter = ''
def nodeFilter = 'eclipse-codesign'
if (buildConfig.TARGET_OS == 'windows') {
filter = '**/OpenJDK*_windows_*.zip'
} else if (buildConfig.TARGET_OS == 'mac') {
filter = '**/OpenJDK*_mac_*.tar.gz'
}
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: 'SIGN_TOOL', value: 'eclipse'),
context.string(name: 'FILTER', value: "${filter}"),
['$class': 'LabelParameterValue', name: 'NODE_LABEL', label: "${nodeFilter}"],
]
// Execute sign job
def signJob = context.build job: 'build-scripts/release/sign_build',
propagate: true,
parameters: params
context.node('worker') {
//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'
// 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.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 Windows installer downstream jobs.
We run two jobs if we have a JRE (see https://github.com/adoptium/temurin-build/issues/1751).
*/
private void buildWindowsInstaller(VersionInfo versionData, String filter, String category) {
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
def INSTALLER_JVM = "${buildConfig.VARIANT}"
// if variant is temurin set param as hotpot
if (buildConfig.VARIANT == 'temurin') {
INSTALLER_JVM = 'hotspot'
}
// 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: "${category}"),
context.string(name: 'JVM', value: "${INSTALLER_JVM}"),
context.string(name: 'ARCH', value: "${INSTALLER_ARCH}"),
]
context.copyArtifacts(
projectName: 'build-scripts/release/create_installer_windows',
selector: context.specific("${installerJob.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('worker') {
context.stage('installer') {
switch (buildConfig.TARGET_OS) {
case 'mac':
context.sh 'rm -rf workspace/target/* || true'
buildMacInstaller(versionData)
break
case 'windows':
context.sh 'rm -rf workspace/target/* || true'
buildWindowsInstaller(versionData, '**/OpenJDK*jdk_*_windows*.zip', 'jdk')
// Copy jre artifact from current pipeline job
context.copyArtifacts(
projectName: "${env.JOB_NAME}",
selector: context.specific("${env.BUILD_NUMBER}"),
filter: '**/OpenJDK*jre_*_windows*.zip',
fingerprintArtifacts: true,
target: 'workspace/target/',
flatten: true)
// Check if JRE exists, if so, build another installer for it
if (listArchives().any { it =~ /-jre/ } ) { buildWindowsInstaller(versionData, '**/OpenJDK*jre_*_windows*.zip', 'jre') }
break
default:
break
}
// Archive the Mac and Windows pkg/msi
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'
setStageResult("installer", 'FAILURE')
}
}
}
}
}
def signInstaller(VersionInfo versionData) {
if (versionData == null || versionData.major == null) {
context.println 'Failed to parse version number, possibly a nightly? Skipping installer steps'
return
}
context.node('worker') {
context.stage('sign installer') {
// Ensure master context workspace is clean of any previous archives
context.sh 'rm -rf workspace/target/* || true'
if (buildConfig.TARGET_OS == 'mac' || buildConfig.TARGET_OS == 'windows') {
try {
signInstallerJob(versionData)
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'
setStageResult("sign installer", 'FAILURE')
}
}
}
}
}
private void signInstallerJob(VersionInfo versionData) {
def filter = ''
switch (buildConfig.TARGET_OS) {
case 'mac': filter = '**/OpenJDK*_mac_*.pkg'; break
case 'windows': filter = '**/OpenJDK*_windows_*.msi'; break
default: break
}
// Execute sign installer job
def installerJob = context.build job: 'build-scripts/release/sign_installer',
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: 'OPERATING_SYSTEM', value: "${buildConfig.TARGET_OS}"),
context.string(name: 'MAJOR_VERSION', value: "${versionData.major}")
]
context.copyArtifacts(
projectName: 'build-scripts/release/sign_installer',
selector: context.specific("${installerJob.getNumber()}"),
filter: 'workspace/target/*',
fingerprintArtifacts: true,
target: 'workspace/target/',
flatten: true)
}
// For Windows and Mac verify that all necessary executables are Signed and Notarized(mac)
private void verifySigning() {
if (buildConfig.TARGET_OS == "windows" || buildConfig.TARGET_OS == "mac") {
context.stage('sign verification') {
try {
context.println "RUNNING sign_verification for ${buildConfig.TARGET_OS}/${buildConfig.ARCHITECTURE} ..."
// Determine suitable node to run on
def verifyNode
if (buildConfig.TARGET_OS == "windows") {
verifyNode = "ci.role.test&&sw.os.windows"
} else {
verifyNode = "ci.role.test&&(sw.os.osx||sw.os.mac)&&!sw.os.osx.10_14"
}
if (buildConfig.ARCHITECTURE == "aarch64") {
verifyNode = verifyNode + "&&hw.arch.aarch64"
} else {
verifyNode = verifyNode + "&&hw.arch.x86"
}