-
-
Notifications
You must be signed in to change notification settings - Fork 71
/
build_base_file.groovy
819 lines (699 loc) · 32.4 KB
/
build_base_file.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
import common.IndividualBuildConfig
import groovy.json.*
import java.util.regex.Matcher
import org.jenkinsci.plugins.workflow.steps.FlowInterruptedException
/*
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.
*/
/**
* Represents parameters that get past to each individual build
*/
/**
* This file starts a high level job, it is called from openjdk_pipeline.groovy.
*
* This:
*
* 1. Generate job for each configuration based on create_job_from_template.groovy
* 2. Execute job
* 3. Push generated artifacts to github
*/
//@CompileStatic(extensions = "JenkinsTypeCheckHelperExtension")
class Builder implements Serializable {
String javaToBuild
Map<String, Map<String, ?>> buildConfigurations
Map<String, List<String>> targetConfigurations
Map<String, ?> DEFAULTS_JSON
String activeNodeTimeout
Map<String, List<String>> dockerExcludes
boolean enableTests
boolean enableInstallers
boolean enableSigner
boolean publish
boolean release
String releaseType
String scmReference
String publishName
String additionalConfigureArgs
def scmVars
String additionalBuildArgs
String overrideFileNameVersion
String adoptBuildNumber
boolean useAdoptShellScripts
boolean cleanWorkspaceBeforeBuild
boolean cleanWorkspaceAfterBuild
boolean cleanWorkspaceBuildOutputAfterBuild
boolean propagateFailures
boolean keepTestReportDir
boolean keepReleaseLogs
def currentBuild
def context
def env
/*
Test targets triggered in 'nightly' build pipelines running 6 days per week
nightly + weekly to be run during a 'release' pipeline
*/
final List<String> nightly = [
'sanity.openjdk',
'sanity.system',
'extended.system',
'sanity.perf',
'sanity.functional',
'extended.functional'
]
/*
Test targets triggered in 'weekly' build pipelines running once per week
nightly + weekly to be run during a 'release' pipeline
*/
final List<String> weekly = [
'extended.openjdk',
'extended.perf',
'special.functional',
'sanity.external'
]
// Declare timeouts for each critical stage (unit is HOURS)
Map pipelineTimeouts = [
API_REQUEST_TIMEOUT : 1,
REMOVE_ARTIFACTS_TIMEOUT : 2,
COPY_ARTIFACTS_TIMEOUT : 6,
ARCHIVE_ARTIFACTS_TIMEOUT : 6,
PUBLISH_ARTIFACTS_TIMEOUT : 3
]
/*
Returns an IndividualBuildConfig that is passed down to the downstream job.
It uses several helper functions to pull in and parse the build configuration for the job.
This overrides the default IndividualBuildConfig generated in config_regeneration.groovy.
*/
IndividualBuildConfig buildConfiguration(Map<String, ?> platformConfig, String variant) {
// 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)
int headVersion = (int) response.getAt("tip_version")
context.println "Found Java Version Number: ${headVersion}"
if (javaToBuild == "jdk${headVersion}") {
javaToBuild = "jdk"
}
def additionalNodeLabels = formAdditionalBuildNodeLabels(platformConfig, variant)
def additionalTestLabels = formAdditionalTestLabels(platformConfig, variant)
def archLabel = getArchLabel(platformConfig, variant)
def dockerImage = getDockerImage(platformConfig, variant)
def dockerFile = getDockerFile(platformConfig, variant)
def dockerNode = getDockerNode(platformConfig, variant)
def platformSpecificConfigPath = getPlatformSpecificConfigPath(platformConfig)
def buildArgs = getBuildArgs(platformConfig, variant)
if (additionalBuildArgs) {
buildArgs += " " + additionalBuildArgs
}
def testList = getTestList(platformConfig)
def platformCleanWorkspaceAfterBuild = getCleanWorkspaceAfterBuild(platformConfig)
// Always clean on mac due to https://github.com/AdoptOpenJDK/openjdk-build/issues/1980
def cleanWorkspace = cleanWorkspaceBeforeBuild
if (platformConfig.os == "mac") {
cleanWorkspace = true
}
def cleanWsAfter = cleanWorkspaceAfterBuild
if (platformCleanWorkspaceAfterBuild) {
// Platform override specified
cleanWsAfter = platformCleanWorkspaceAfterBuild
}
return new IndividualBuildConfig(
JAVA_TO_BUILD: javaToBuild,
ARCHITECTURE: platformConfig.arch as String,
TARGET_OS: platformConfig.os as String,
VARIANT: variant,
TEST_LIST: testList,
SCM_REF: scmReference,
BUILD_ARGS: buildArgs,
NODE_LABEL: "${additionalNodeLabels}&&${platformConfig.os}&&${archLabel}",
ADDITIONAL_TEST_LABEL: "${additionalTestLabels}",
KEEP_TEST_REPORTDIR: keepTestReportDir,
ACTIVE_NODE_TIMEOUT: activeNodeTimeout,
CODEBUILD: platformConfig.codebuild as Boolean,
DOCKER_IMAGE: dockerImage,
DOCKER_FILE: dockerFile,
DOCKER_NODE: dockerNode,
PLATFORM_CONFIG_LOCATION: platformSpecificConfigPath,
CONFIGURE_ARGS: getConfigureArgs(platformConfig, additionalConfigureArgs, variant),
OVERRIDE_FILE_NAME_VERSION: overrideFileNameVersion,
USE_ADOPT_SHELL_SCRIPTS: useAdoptShellScripts,
ADDITIONAL_FILE_NAME_TAG: platformConfig.additionalFileNameTag as String,
JDK_BOOT_VERSION: platformConfig.bootJDK as String,
RELEASE: release,
PUBLISH_NAME: publishName,
ADOPT_BUILD_NUMBER: adoptBuildNumber,
ENABLE_TESTS: enableTests,
ENABLE_INSTALLERS: enableInstallers,
ENABLE_SIGNER: enableSigner,
CLEAN_WORKSPACE: cleanWorkspace,
CLEAN_WORKSPACE_AFTER: cleanWsAfter,
CLEAN_WORKSPACE_BUILD_OUTPUT_ONLY_AFTER: cleanWorkspaceBuildOutputAfterBuild
)
}
/*
Returns true if possibleMap is a Map. False otherwise.
*/
static def isMap(possibleMap) {
return Map.class.isInstance(possibleMap)
}
/*
Retrieves the buildArgs attribute from the build configurations.
These eventually get passed to ./makejdk-any-platform.sh and make images.
*/
String getBuildArgs(Map<String, ?> configuration, variant) {
if (configuration.containsKey('buildArgs')) {
if (isMap(configuration.buildArgs)) {
Map<String, ?> buildArgs = configuration.buildArgs as Map<String, ?>
if (buildArgs.containsKey(variant)) {
return buildArgs.get(variant)
}
} else {
return configuration.buildArgs
}
}
return ""
}
/*
Get the list of tests to run from the build configurations.
We run different test categories depending on if this build is a release or nightly. This function parses and applies this to the individual build config.
*/
List<String> getTestList(Map<String, ?> configuration) {
List<String> testList = []
/*
* No test key or key value is test: false --- test disabled
* Key value is test: 'default' --- nightly build trigger 'nightly' test set, weekly build trigger or release build trigger 'nightly' + 'weekly' test sets
* Key value is test: [customized map] specified nightly and weekly test lists
*/
if (configuration.containsKey("test") && configuration.get("test")) {
def testJobType = "nightly"
if (releaseType.equals("Weekly") || releaseType.equals("Release")) {
testJobType = "weekly"
}
if (isMap(configuration.test)) {
if ( testJobType == "nightly" ) {
testList = (configuration.test as Map).get("nightly") as List<String>
} else {
testList = ((configuration.test as Map).get("nightly") as List<String>) + ((configuration.test as Map).get("weekly") as List<String>)
}
} else {
// Default to the test sets declared if one isn't set in the build configuration
if ( testJobType == "nightly" ) {
testList = nightly
} else {
testList = nightly + weekly
}
}
}
testList.unique()
return testList
}
/*
Get the cleanWorkspaceAfterBuild override for this platform configuration
*/
Boolean getCleanWorkspaceAfterBuild(Map<String, ?> configuration) {
Boolean cleanWorkspaceAfterBuild = null
if (configuration.containsKey("cleanWorkspaceAfterBuild") && configuration.get("cleanWorkspaceAfterBuild")) {
cleanWorkspaceAfterBuild = configuration.cleanWorkspaceAfterBuild as Boolean
}
return cleanWorkspaceAfterBuild
}
/*
Parses and applies the dockerExcludes parameter.
Any platforms/variants that are declared in this parameter are marked as excluded from docker building via this function. Even if they have a docker image or file declared in the build configurations!
*/
def dockerOverride(Map<String, ?> configuration, String variant) {
Boolean overrideDocker = false
if (dockerExcludes == {}) {
return overrideDocker
}
String stringArch = configuration.arch as String
String stringOs = configuration.os as String
String estimatedKey = stringArch + stringOs.capitalize()
if (configuration.containsKey("additionalFileNameTag")) {
estimatedKey = estimatedKey + "XL"
}
if (dockerExcludes.containsKey(estimatedKey)) {
if (dockerExcludes[estimatedKey].contains(variant)) {
overrideDocker = true
}
}
return overrideDocker
}
def getArchLabel(Map<String, ?> configuration, String variant) {
def archLabelVal = ""
// Workaround for cross compiled architectures
if (configuration.containsKey("crossCompile")) {
archLabelVal = configuration.crossCompile
} else {
archLabelVal = configuration.arch
}
return archLabelVal
}
/*
Retrieves the dockerImage attribute from the build configurations.
This specifies the DockerHub org and image to pull or build in case we don't have one stored in this repository.
If this isn't specified, the openjdk_build_pipeline.groovy will assume we are not building the jdk inside of a container.
*/
def getDockerImage(Map<String, ?> configuration, String variant) {
def dockerImageValue = ""
if (configuration.containsKey("dockerImage") && !dockerOverride(configuration, variant)) {
if (isMap(configuration.dockerImage)) {
dockerImageValue = (configuration.dockerImage as Map<String, ?>).get(variant)
} else {
dockerImageValue = configuration.dockerImage
}
}
return dockerImageValue
}
/*
Retrieves the dockerFile attribute from the build configurations.
This specifies the path of the dockerFile relative to this repository.
If a dockerFile is not specified, the openjdk_build_pipeline.groovy will attempt to pull one from DockerHub.
*/
def getDockerFile(Map<String, ?> configuration, String variant) {
def dockerFileValue = ""
if (configuration.containsKey("dockerFile") && !dockerOverride(configuration, variant)) {
if (isMap(configuration.dockerFile)) {
dockerFileValue = (configuration.dockerFile as Map<String, ?>).get(variant)
} else {
dockerFileValue = configuration.dockerFile
}
}
return dockerFileValue
}
/*
Retrieves the dockerNode attribute from the build configurations.
This determines what the additional label will be if we are building the jdk in a docker container.
Defaults to &&dockerBuild in openjdk_build_pipeline.groovy if it's not supplied in the build configuration.
*/
def getDockerNode(Map<String, ?> configuration, String variant) {
def dockerNodeValue = ""
if (configuration.containsKey("dockerNode")) {
if (isMap(configuration.dockerNode)) {
dockerNodeValue = (configuration.dockerNode as Map<String, ?>).get(variant)
} else {
dockerNodeValue = configuration.dockerNode
}
}
return dockerNodeValue
}
/*
Retrieves the platformSpecificConfigPath from the build configurations.
This determines where the location of the operating system setup files are in comparison to the repository root. The param is formatted like this because we need to download and source the file from the bash scripts.
*/
def getPlatformSpecificConfigPath(Map<String, ?> configuration) {
def splitUserUrl = ((String)DEFAULTS_JSON['repository']['build_url']).minus(".git").split('/')
// e.g. https://github.com/AdoptOpenJDK/openjdk-build.git will produce AdoptOpenJDK/openjdk-build
String userOrgRepo = "${splitUserUrl[splitUserUrl.size() - 2]}/${splitUserUrl[splitUserUrl.size() - 1]}"
// e.g. AdoptOpenJDK/openjdk-build/master/build-farm/platform-specific-configurations
def platformSpecificConfigPath = "${userOrgRepo}/${DEFAULTS_JSON['repository']['build_branch']}/${DEFAULTS_JSON['configDirectories']['platform']}"
if (configuration.containsKey("platformSpecificConfigPath")) {
// e.g. AdoptOpenJDK/openjdk-build/master/build-farm/platform-specific-configurations.linux.sh
platformSpecificConfigPath = "${userOrgRepo}/${DEFAULTS_JSON['repository']['build_branch']}/${configuration.platformSpecificConfigPath}"
}
return platformSpecificConfigPath
}
/*
Constructs any necessary additional build labels from the build configurations.
This builds up a node param string that defines what nodes are eligible to run the given job.
*/
def formAdditionalBuildNodeLabels(Map<String, ?> configuration, String variant) {
def buildTag = "build"
def labels = "${buildTag}"
if (configuration.containsKey("additionalNodeLabels")) {
def additionalNodeLabels
if (isMap(configuration.additionalNodeLabels)) {
additionalNodeLabels = (configuration.additionalNodeLabels as Map<String, ?>).get(variant)
} else {
additionalNodeLabels = configuration.additionalNodeLabels
}
if (additionalNodeLabels != null) {
labels = "${additionalNodeLabels}&&${labels}"
}
}
return labels
}
/**
* Builds up additional test labels
* @param configuration
* @param variant
* @return
*/
def formAdditionalTestLabels(Map<String, ?> configuration, String variant) {
def labels = ""
if (configuration.containsKey("additionalTestLabels")) {
def additionalTestLabels
if (isMap(configuration.additionalTestLabels)) {
additionalTestLabels = (configuration.additionalTestLabels as Map<String, ?>).get(variant)
} else {
additionalTestLabels = configuration.additionalTestLabels
}
if (additionalTestLabels != null) {
labels = "${additionalTestLabels}"
}
}
return labels
}
/*
Retrieves the configureArgs attribute from the build configurations.
These eventually get passed to ./makejdk-any-platform.sh and bash configure.
*/
static String getConfigureArgs(Map<String, ?> configuration, String additionalConfigureArgs, String variant) {
def configureArgs = ""
if (configuration.containsKey('configureArgs')) {
def configConfigureArgs
if (isMap(configuration.configureArgs)) {
configConfigureArgs = (configuration.configureArgs as Map<String, ?>).get(variant)
} else {
configConfigureArgs = configuration.configureArgs
}
if (configConfigureArgs != null) {
configureArgs += configConfigureArgs
}
}
if (additionalConfigureArgs) {
configureArgs += " " + additionalConfigureArgs
}
return configureArgs
}
/*
Imports the build configurations for the target version based off its key and variant.
E.g. { "x64Linux" : [ "hotspot", "openj9" ] }
*/
Map<String, IndividualBuildConfig> getJobConfigurations() {
Map<String, IndividualBuildConfig> jobConfigurations = [:]
//Parse nightly config passed to jenkins job
targetConfigurations
.each { target ->
//For each requested build type, generate a configuration
if (buildConfigurations.containsKey(target.key)) {
def platformConfig = buildConfigurations.get(target.key) as Map<String, ?>
target.value.each { variant ->
// Construct a rough job name from the build config and variant
String name = "${platformConfig.os}-${platformConfig.arch}-${variant}"
if (platformConfig.containsKey('additionalFileNameTag')) {
name += "-${platformConfig.additionalFileNameTag}"
}
// Fill in the name's value with an IndividualBuildConfig
jobConfigurations[name] = buildConfiguration(platformConfig, variant)
}
}
}
return jobConfigurations
}
/*
Returns the JDK head number from the Adopt API
*/
Integer getHeadVersionNumber() {
try {
context.timeout(time: pipelineTimeouts.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)
return (int) response.getAt("tip_version")
}
} catch (FlowInterruptedException e) {
throw new Exception("[ERROR] Adopt API Request timeout (${pipelineTimeouts.API_REQUEST_TIMEOUT} HOURS) has been reached. Exiting...")
}
}
/*
Returns the java version number for this pipeline (e.g. 8, 11, 15, 16)
*/
Integer getJavaVersionNumber() {
// 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())) {
return getHeadVersionNumber()
} else {
throw new Exception("Failed to read java version '${javaToBuild}'")
}
}
/*
Returns the release tool version string to use in the release job
*/
def determineReleaseToolRepoVersion() {
def number = getJavaVersionNumber()
return "jdk${number}"
}
/*
Returns the job name of the target downstream job
*/
def getJobName(displayName) {
return "${javaToBuild}-${displayName}"
}
/*
Returns the jenkins folder of where it's assumed the downstream build jobs have been regenerated
*/
def getJobFolder() {
def parentDir = currentBuild.fullProjectName.substring(0, currentBuild.fullProjectName.lastIndexOf("/"))
return parentDir + "/jobs/" + javaToBuild
}
/*
Ensures that we don't release multiple variants at the same time
Unless this is the weekend weekly release build that won't have a publishName
*/
def checkConfigIsSane(Map<String, IndividualBuildConfig> jobConfigurations) {
if (release && publishName) {
// Doing a release
def variants = jobConfigurations
.values()
.collect({ it.VARIANT })
.unique()
if (variants.size() > 1) {
context.error('Trying to release multiple variants at the same time, this is unusual')
return false
}
}
return true
}
/*
Call job to push artifacts to github. Usually it's only executed on a nightly build
*/
def publishBinary() {
if (release) {
// make sure to skip on release
context.println("Not publishing release")
return
}
def timestamp = new Date().format("yyyy-MM-dd-HH-mm", TimeZone.getTimeZone("UTC"))
def tag = "${javaToBuild}-${timestamp}"
if (publishName) {
tag = publishName
}
context.stage("publish") {
context.build job: 'build-scripts/release/refactor_openjdk_release_tool',
parameters: [
['$class': 'BooleanParameterValue', name: 'RELEASE', value: release],
context.string(name: 'TAG', value: tag),
context.string(name: 'TIMESTAMP', value: timestamp),
context.string(name: 'UPSTREAM_JOB_NAME', value: env.JOB_NAME),
context.string(name: 'UPSTREAM_JOB_NUMBER', value: "${currentBuild.getNumber()}"),
context.string(name: 'VERSION', value: determineReleaseToolRepoVersion())
]
}
}
/*
Main function. This is what is executed remotely via the openjdkxx-pipeline and pr tester jobs
*/
@SuppressWarnings("unused")
def doBuild() {
context.timestamps {
Map<String, IndividualBuildConfig> jobConfigurations = getJobConfigurations()
if (!checkConfigIsSane(jobConfigurations)) {
return
}
if (release) {
if (publishName) {
// Keep Jenkins release logs for real releases
currentBuild.setKeepLog(keepReleaseLogs)
currentBuild.setDisplayName(publishName)
}
}
def jobs = [:]
// Special case for JDK head where the jobs are called jdk-os-arch-variant
if (javaToBuild == "jdk${getHeadVersionNumber()}") {
javaToBuild = "jdk"
}
context.echo "Java: ${javaToBuild}"
context.echo "OS: ${targetConfigurations}"
context.echo "Enable tests: ${enableTests}"
context.echo "Enable Installers: ${enableInstallers}"
context.echo "Enable Signer: ${enableSigner}"
context.echo "Use Adopt's Scripts: ${useAdoptShellScripts}"
context.echo "Publish: ${publish}"
context.echo "Release: ${release}"
context.echo "Tag/Branch name: ${scmReference}"
context.echo "Keep test reportdir: ${keepTestReportDir}"
context.echo "Keep release logs: ${keepReleaseLogs}"
jobConfigurations.each { configuration ->
jobs[configuration.key] = {
IndividualBuildConfig config = configuration.value
// jdk11u-linux-x64-hotspot
def jobTopName = getJobName(configuration.key)
def jobFolder = getJobFolder()
// i.e jdk11u/job/jdk11u-linux-x64-hotspot
def downstreamJobName = "${jobFolder}/${jobTopName}"
context.echo "build name " + downstreamJobName
context.catchError {
// Execute build job for configuration i.e jdk11u/job/jdk11u-linux-x64-hotspot
context.stage(configuration.key) {
context.echo "Created job " + downstreamJobName
// execute build
def downstreamJob = context.build job: downstreamJobName, propagate: false, parameters: config.toBuildParams()
if (downstreamJob.getResult() == 'SUCCESS') {
// copy artifacts from build
context.println "[NODE SHIFT] MOVING INTO MASTER NODE..."
context.node("master") {
context.catchError {
//Remove the previous artifacts
try {
context.timeout(time: pipelineTimeouts.REMOVE_ARTIFACTS_TIMEOUT, unit: "HOURS") {
context.sh "rm target/${config.TARGET_OS}/${config.ARCHITECTURE}/${config.VARIANT}/* || true"
}
} catch (FlowInterruptedException e) {
throw new Exception("[ERROR] Previous artifact removal timeout (${pipelineTimeouts.REMOVE_ARTIFACTS_TIMEOUT} HOURS) for ${downstreamJobName} has been reached. Exiting...")
}
try {
context.timeout(time: pipelineTimeouts.COPY_ARTIFACTS_TIMEOUT, unit: "HOURS") {
context.copyArtifacts(
projectName: downstreamJobName,
selector: context.specific("${downstreamJob.getNumber()}"),
filter: 'workspace/target/*',
fingerprintArtifacts: true,
target: "target/${config.TARGET_OS}/${config.ARCHITECTURE}/${config.VARIANT}/",
flatten: true
)
}
} catch (FlowInterruptedException e) {
throw new Exception("[ERROR] Copy artifact timeout (${pipelineTimeouts.COPY_ARTIFACTS_TIMEOUT} HOURS) for ${downstreamJobName} has been reached. Exiting...")
}
// Checksum
context.sh 'for file in $(ls target/*/*/*/*.tar.gz target/*/*/*/*.zip); do sha256sum "$file" > $file.sha256.txt ; done'
// Archive in Jenkins
try {
context.timeout(time: pipelineTimeouts.ARCHIVE_ARTIFACTS_TIMEOUT, unit: "HOURS") {
context.archiveArtifacts artifacts: "target/${config.TARGET_OS}/${config.ARCHITECTURE}/${config.VARIANT}/*"
}
} catch (FlowInterruptedException e) {
throw new Exception("[ERROR] Archive artifact timeout (${pipelineTimeouts.ARCHIVE_ARTIFACTS_TIMEOUT} HOURS) for ${downstreamJobName}has been reached. Exiting...")
}
}
}
context.println "[NODE SHIFT] OUT OF MASTER NODE!"
} else if (propagateFailures) {
context.error("Build failed due to downstream failure of ${downstreamJobName}")
currentBuild.result = "FAILURE"
}
}
}
}
}
context.parallel jobs
// publish to github if needed
// Dont publish release automatically
if (publish && !release) {
//During testing just remove the publish
try {
context.timeout(time: pipelineTimeouts.PUBLISH_ARTIFACTS_TIMEOUT, unit: "HOURS") {
publishBinary()
}
} catch (FlowInterruptedException e) {
throw new Exception("[ERROR] Publish binary timeout (${pipelineTimeouts.PUBLISH_ARTIFACTS_TIMEOUT} HOURS) has been reached OR the downstream publish job failed. Exiting...")
}
} else if (publish && release) {
context.println "NOT PUBLISHING RELEASE AUTOMATICALLY"
}
}
}
}
return {
String javaToBuild,
Map<String, Map<String, ?>> buildConfigurations,
String targetConfigurations,
Map<String, ?> DEFAULTS_JSON,
String activeNodeTimeout,
String dockerExcludes,
String enableTests,
String enableInstallers,
String enableSigner,
String releaseType,
String scmReference,
String overridePublishName,
String useAdoptShellScripts,
String additionalConfigureArgs,
def scmVars,
String additionalBuildArgs,
String overrideFileNameVersion,
String cleanWorkspaceBeforeBuild,
String cleanWorkspaceAfterBuild,
String cleanWorkspaceBuildOutputAfterBuild,
String adoptBuildNumber,
String propagateFailures,
String keepTestReportDir,
String keepReleaseLogs,
def currentBuild,
def context,
def env ->
boolean release = false
if (releaseType == 'Release') {
release = true
}
boolean publish = false
if (releaseType == 'Nightly' || releaseType == 'Weekly') {
publish = true
}
String publishName = '' // This is set to a timestamp later on if undefined
if (overridePublishName) {
publishName = overridePublishName
} else if (release) {
// Default to scmReference, remove any trailing "_adopt" from the tag if present
if (scmReference) {
publishName = scmReference.minus("_adopt")
}
}
def buildsExcludeDocker = [:]
if (dockerExcludes != "" && dockerExcludes != null) {
buildsExcludeDocker = new JsonSlurper().parseText(dockerExcludes) as Map
}
return new Builder(
javaToBuild: javaToBuild,
buildConfigurations: buildConfigurations,
targetConfigurations: new JsonSlurper().parseText(targetConfigurations) as Map,
DEFAULTS_JSON: DEFAULTS_JSON,
activeNodeTimeout: activeNodeTimeout,
dockerExcludes: buildsExcludeDocker,
enableTests: Boolean.parseBoolean(enableTests),
enableInstallers: Boolean.parseBoolean(enableInstallers),
enableSigner: Boolean.parseBoolean(enableSigner),
publish: publish,
release: release,
releaseType: releaseType,
scmReference: scmReference,
publishName: publishName,
additionalConfigureArgs: additionalConfigureArgs,
scmVars: scmVars,
additionalBuildArgs: additionalBuildArgs,
overrideFileNameVersion: overrideFileNameVersion,
useAdoptShellScripts: Boolean.parseBoolean(useAdoptShellScripts),
cleanWorkspaceBeforeBuild: Boolean.parseBoolean(cleanWorkspaceBeforeBuild),
cleanWorkspaceAfterBuild: Boolean.parseBoolean(cleanWorkspaceAfterBuild),
cleanWorkspaceBuildOutputAfterBuild: Boolean.parseBoolean(cleanWorkspaceBuildOutputAfterBuild),
adoptBuildNumber: adoptBuildNumber,
propagateFailures: Boolean.parseBoolean(propagateFailures),
keepTestReportDir: Boolean.parseBoolean(keepTestReportDir),
keepReleaseLogs: Boolean.parseBoolean(keepReleaseLogs),
currentBuild: currentBuild,
context: context,
env: env
)
}