-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathJenkinsfile
More file actions
458 lines (417 loc) · 18.6 KB
/
Jenkinsfile
File metadata and controls
458 lines (417 loc) · 18.6 KB
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
/*
* Copyright IBM Corp. 2024, 2026
*
* This code is free software; you can redistribute it and/or modify it
* under the terms provided by IBM in the LICENSE file that accompanied
* this code, including the "Classpath" Exception described therein.
*/
import groovy.json.JsonOutput;
import groovy.transform.Field;
@Field boolean PPC64_AIX
@Field boolean X86_64_LINUX
@Field boolean PPC64LE_LINUX
@Field boolean S390X_LINUX
@Field boolean X86_64_WINDOWS
@Field boolean AARCH64_MAC
@Field boolean X86_64_MAC
@Field boolean AARCH64_LINUX
@Field OPENJCEPLUS_REPO
@Field OPENJCEPLUS_BRANCH
@Field JAVA_VERSION
@Field JAVA_RELEASE
@Field OCK_RELEASE
@Field OCK_FULL_URL
@Field EXECUTE_TESTS
@Field SPECIFIC_TEST
@Field PARALLEL_ITERATIONS
@Field ADDITIONAL_NODE_LABELS
@Field OVERRIDE_NODE_LABELS
@Field ADDITIONAL_ENVARS
@Field ADDITIONAL_CMD_ARGS
@Field TIMEOUT_TIME
@Field externalLibrary
/*
* Clone the branch from the repo specified to
* get the appropriate OpenJCEPlus code to build.
*/
def cloneOpenJCEPlus() {
dir("openjceplus/OpenJCEPlus") {
if ((OPENJCEPLUS_REPO == "") && (OPENJCEPLUS_BRANCH == "")) {
echo "Clone using default branch and repository."
checkout scm
} else {
echo "Clone using ${OPENJCEPLUS_BRANCH} from ${OPENJCEPLUS_REPO}"
git branch: "${OPENJCEPLUS_BRANCH}", url: "${OPENJCEPLUS_REPO}"
}
}
}
/*
* Checks the checkboxes to figure out the platforms
* selected to build OpenJCEPlus on.
*
* @return The platforms to build OpenJCEPlus on
*/
def getPlatforms() {
def platforms = []
if (PPC64_AIX == "true") {
platforms.add("ppc64_aix")
}
if (X86_64_LINUX == "true") {
platforms.add("x86-64_linux")
}
if (PPC64LE_LINUX == "true") {
platforms.add("ppc64le_linux")
}
if (S390X_LINUX == "true") {
platforms.add("s390x_linux")
}
if (X86_64_WINDOWS == "true") {
platforms.add("x86-64_windows")
}
if (AARCH64_MAC == "true") {
platforms.add("aarch64_mac")
}
if (X86_64_MAC == "true") {
platforms.add("x86-64_mac")
}
if (AARCH64_LINUX == "true") {
platforms.add("aarch64_linux")
}
return platforms
}
/*
* Get the appropriate test flag.
*
* The user might have requested that test are not
* run or asked for a specific test to
* be executed.
*
* Even if that's not the case, in some
* platforms the OpenJCEPlusFIPS provider is not
* available and thus the FIPS-related tests should
* not be executed.
*/
def getTestFlag(hardware, software) {
// User requested that tests not be executed.
if (EXECUTE_TESTS == "false") {
return " -DskipTests"
}
// User requested execution of a specific test.
if (SPECIFIC_TEST) {
return " -Dtest=${SPECIFIC_TEST}"
}
// Run all tests. Some platforms will naturally run in developer mode.
echo "All tests (both FIPS and non-FIPS) can be run in ${hardware}_${software}"
return "";
}
/*
* Creates the upload specification and triggers the process
* of uploading the compressed file to Artifactory.
*
* @param platform The platform for which OpenJCEPlus was built
* @return The URL to the uploaded file
*/
def archive(platform, iteration) {
// Create compressed file containing build.
def ending = ".tar.gz"
def filename = "openjceplus-$iteration-$platform$ending"
dir("openjceplus/OpenJCEPlus") {
tar archive: false, compress: true, defaultExcludes: false, dir: '', exclude: '', file: "$filename", glob: '', overwrite: false
}
// Set the specific specifications to upload build.
def buildID = "${env.BUILD_ID}"
def fileLocation = "$WORKSPACE/openjceplus/OpenJCEPlus"
def sanitizedBranchName = externalLibrary.getSanitizedBranchName()
def directory = "sys-rt-generic-local/OpenJCEPlus_builds/buildtest/$sanitizedBranchName/$buildID"
// The OpenJCEPlus repo to be used
def repo = "NULL"
if (OPENJCEPLUS_REPO == "") {
repo = env.GIT_URL
} else {
repo = OPENJCEPLUS_REPO
}
// The OpenJCEPlus branch to be used
def branch = "NULL"
if (OPENJCEPLUS_BRANCH == "") {
branch = env.GIT_BRANCH
} else {
branch = OPENJCEPLUS_BRANCH
}
def specs = []
def spec = ["pattern": "$fileLocation/$filename",
"target": "$directory/$filename",
"props": "java_release=$JAVA_RELEASE;ock_release=$OCK_RELEASE;repo=$repo;branch=$branch"]
specs.add(spec)
def uploadFiles = [files : specs]
def uploadSpec = JsonOutput.toJson(uploadFiles)
// Upload compressed build.
def serverUrl = externalLibrary.upload_artifactory(uploadSpec)
def fileUrl = "$serverUrl/$directory/$filename"
echo "Compressed and uploaded target for $branch of $repo: $fileUrl"
// Add it to the description for quick access.
currentBuild.description += "<br><a href=$fileUrl>$filename</a>"
}
/*
* Figure out the appropriate node tags based on the platform and
* execute the whole pipeline on a node that conforms to them.
*
* @param platform The platform for which OpenJCEPlus will be built
* @return The node that will perform the build
*/
def run(platform) {
def platformArray = platform.split("_")
def hardware = platformArray[0]
def software = platformArray[1]
def node_hardware = hardware
if (hardware.contains('x86')) {
node_hardware = "x86"
}
def node_software = software
if (software == "windows") {
node_software = "windows.2022"
}
return {
def excludeNode = []
def iteration = 0
retry(3) {
// Specific labels are selected based on platform.
def nodeTags = "hw.arch.${node_hardware}&&sw.os.${node_software}"
// Nodes where a failed attempt was made are excluded.
excludeNode.each { nodeTags += "&&!" + it }
// Some OSes have some further specific requirements.
if (software == "aix") {
// Java 25+ requires C++17.1 runtime. Otherwise crashes occur.
nodeTags = "hw.arch.${node_hardware}&&sw.os.aix.7_2&&sw.tool.c++runtime.17_1&&ci.role.build"
} else {
// Machines tagged as ci.role.test are expected to have
// software to compile, build, and test OpenJCEPlus.
nodeTags += "&&ci.role.test"
// Exclude machines that are FIPS140-2 configured.
nodeTags += "&&!ci.role.test.fips"
}
// Add additional labels specified by user.
nodeTags += (ADDITIONAL_NODE_LABELS) ? "&&" + ADDITIONAL_NODE_LABELS : ""
// Override labels as specified by user.
nodeTags = (OVERRIDE_NODE_LABELS) ?: nodeTags
echo "${nodeTags}"
node("$nodeTags") {
cloneOpenJCEPlus()
echo "OpenJCEPlus cloned"
dir("openjceplus/OpenJCEPlus") {
externalLibrary = load("./utils.groovy")
}
try {
withCredentials([usernamePassword(credentialsId: '7c1c2c28-650f-49e0-afd1-ca6b60479546', passwordVariable: 'ARTIFACTORY_PASSWORD', usernameVariable: 'ARTIFACTORY_USERNAME')]) {
externalLibrary.getJava(hardware, software)
}
echo "Java fetched"
externalLibrary.getBinaries(hardware, software)
echo "Binaries fetched"
externalLibrary.getMaven()
echo "Maven fetched"
def command = "install"
command += getTestFlag(hardware, software)
externalLibrary.runOpenJCEPlus(command, software)
echo "OpenJCEPlus built"
} finally {
iteration++
try {
archive(platform, iteration)
echo "OpenJCEPlus archived"
} finally {
cleanWs()
}
}
}
}
}
}
/*
* Allows the user to build and optionally test specific OpenJCEPlus repos and
* branches in multiple platforms and Java versions. The OCK release or binary
* used can be specified or default to the latest version.
* After successful completion of the build, the result is compressed
* and uploaded into Artifactory, for personal use or use by other pipelines.
*/
pipeline {
options {
buildDiscarder(logRotator(numToKeepStr: '100'))
}
parameters {
separator(name: "TargetPlatforms", sectionHeader: "Target Platforms",
separatorStyle: "border-width: 0",
sectionHeaderStyle: """
background-color: rgb(24, 42, 118);
text-align: center;
padding: 4px;
color: rgb(255, 255, 255);
font-size: 22px;
font-weight: normal;
text-transform: uppercase;
font-family: 'Orienta', sans-serif;
letter-spacing: 1px;
font-style: italic;
"""
)
booleanParam(name: 'ppc64_aix', defaultValue: false, description: '\
Build for ppc64_aix platform')
booleanParam(name: 'x86_64_linux', defaultValue: false, description: '\
Build for x86-64_linux platform')
booleanParam(name: 'ppc64le_linux', defaultValue: false, description: '\
Build for ppc64le_linux platform')
booleanParam(name: 's390x_linux', defaultValue: false, description: '\
Build for s390x_linux platform')
booleanParam(name: 'x86_64_windows', defaultValue: false, description: '\
Build for x86-64_windows platform')
booleanParam(name: 'aarch64_mac', defaultValue: false, description: '\
Build for aarch64_mac platform')
booleanParam(name: 'x86_64_mac', defaultValue: false, description: '\
Build for x86-64_mac platform')
booleanParam(name: 'aarch64_linux', defaultValue: false, description: '\
Build for aarch64_linux platform')
separator(name: "BuildAndTestPlatforms", sectionHeader: "Build And Test Options",
separatorStyle: "border-width: 0",
sectionHeaderStyle: """
background-color: rgb(24, 42, 118);
text-align: center;
padding: 4px;
color: rgb(255, 255, 255);
font-size: 22px;
font-weight: normal;
text-transform: uppercase;
font-family: 'Orienta', sans-serif;
letter-spacing: 1px;
font-style: italic;
"""
)
string(name: 'OPENJCEPLUS_REPO', defaultValue: '', description: '\
The OpenJCEPlus repo to be used. When not specified this will default to the repository scanned by this multibranch pipeline.\
Typically this will use https://github.com/IBM/OpenJCEPlus')
string(name: 'OPENJCEPLUS_BRANCH', defaultValue: '', description: '\
The OpenJCEPlus branch to be used. When not specified this will default to the branch scanned by this multibranch pipeline.')
string(name: 'JAVA_VERSION', defaultValue: '26', description: '\
Specify the Java version your branch uses to build.')
string(name: 'JAVA_RELEASE', defaultValue: '', description: '\
Indicate a specific Java release that you want to use to build your branch.<br> \
If left empty, the default release for the chosen version will be used.<br> \
Specify the full name of the release.<br> \
(i.e., jdk-<jdk version>_openj9-<openj9 version> => eg., jdk-21.0.2+13_openj9-0.43.0)')
string(name: 'OCK_RELEASE', defaultValue: '', description: '\
Indicate the specific release of the OCK binaries that you want to use to build your branch.<br> \
If left empty, the latest release will be used.<br> \
Specify the full name of the release.<br> \
(i.e., <release date(YYYYMMDD)>_<OCK version> => eg., 20230802_8.9.5) \
')
string(name: 'OCK_FULL_URL', defaultValue: '', description: ' \
This parameter can be used if one wants to specify the full URL from which to get OCK.<br> \
BEWARE: This can only be used with a single platform and it overrides OCK_RELEASE. \
')
separator(name: "TestOptions", sectionHeader: "Test Options",
separatorStyle: "border-width: 0",
sectionHeaderStyle: """
background-color: rgb(24, 42, 118);
text-align: center;
padding: 4px;
color: rgb(255, 255, 255);
font-size: 22px;
font-weight: normal;
text-transform: uppercase;
font-family: 'Orienta', sans-serif;
letter-spacing: 1px;
font-style: italic;
"""
)
booleanParam(name: 'EXECUTE_TESTS', defaultValue: true, description:'\
Execute tests during the build')
string(name: 'SPECIFIC_TEST', defaultValue: '', description: '\
Set this to only execute a specific test, instead of the whole test suite.<br> \
Keep in mind that EXECUTE_TESTS has to be set too for this to work.')
string(name: 'PARALLEL_ITERATIONS', defaultValue: '', description: '\
Number of iterations to run all stages for each of the specified platforms. The iterations will run in parallel.')
separator(name: "ExtendedOptions", sectionHeader: "Extended Options",
separatorStyle: "border-width: 0",
sectionHeaderStyle: """
background-color: rgb(24, 42, 118);
text-align: center;
padding: 4px;
color: rgb(255, 255, 255);
font-size: 22px;
font-weight: normal;
text-transform: uppercase;
font-family: 'Orienta', sans-serif;
letter-spacing: 1px;
font-style: italic;
"""
)
string(name: 'ADDITIONAL_NODE_LABELS', defaultValue: '', description: '\
Additional labels for the node to be used can be defined here.<br> \
These labels will be added to the automatically generated ones, pertaining to platform specified.')
string(name: 'OVERRIDE_NODE_LABELS', defaultValue: '', description: '\
The labels specified will override any other labels chosen and will be the only ones utilized.')
string(name: 'ADDITIONAL_ENVARS', defaultValue: '', description: '\
Additional environment variables that one might want to add to the existing ones.<br> \
Specify them in comma-separated pairs of name and value (e.g. ENVAR1=value1, ENVAR2=value2, ...).<br><br> \
Beware of what you add as it might be overriding existing environment variables.<br> \
NOTE: those will be added to all selected platforms.')
string(name: 'ADDITIONAL_CMD_ARGS', defaultValue: '', description: '\
Additional command line arguments that one might want to add to the mvn command.<br> \
The contents of this will directly be appended to the mvn command, so write exactly as \
you would if running this manually in a command line (e.g., -Dflag1=true -Dflag2=false ...).')
string(name: 'TIMEOUT_TIME', defaultValue: '6', description: '\
Overall build timeout (HOURS)')
}
agent none
stages {
stage('Build And Test OpenJCEPlus') {
steps {
timestamps {
script {
// Set values for various variables associated with the parameters
// of the job. We set these since the default values when the job is
// run the first time is not yet set without explictly setting them.
PPC64_AIX = "${params.ppc64_aix}"
X86_64_LINUX = "${params.x86_64_linux}"
PPC64LE_LINUX="${params.ppc64le_linux}"
S390X_LINUX="${params.s390x_linux}"
X86_64_WINDOWS="${params.x86_64_windows}"
AARCH64_MAC="${params.aarch64_mac}"
X86_64_MAC="${params.x86_64_mac}"
AARCH64_LINUX="${params.aarch64_linux}"
OPENJCEPLUS_REPO="${params.OPENJCEPLUS_REPO}"
OPENJCEPLUS_BRANCH="${params.OPENJCEPLUS_BRANCH}"
JAVA_VERSION="${params.JAVA_VERSION}"
JAVA_RELEASE="${params.JAVA_RELEASE}"
OCK_RELEASE="${params.OCK_RELEASE}"
OCK_FULL_URL="${params.OCK_FULL_URL}"
EXECUTE_TESTS="${params.EXECUTE_TESTS}"
SPECIFIC_TEST="${params.SPECIFIC_TEST}"
PARALLEL_ITERATIONS="${params.PARALLEL_ITERATIONS}"
ADDITIONAL_NODE_LABELS="${params.ADDITIONAL_NODE_LABELS}"
OVERRIDE_NODE_LABELS="${params.OVERRIDE_NODE_LABELS}"
ADDITIONAL_ENVARS="${params.ADDITIONAL_ENVARS}"
ADDITIONAL_CMD_ARGS="${params.ADDITIONAL_CMD_ARGS}"
TIMEOUT_TIME="${params.TIMEOUT_TIME}"
timeout(time: "${TIMEOUT_TIME}".toInteger(), unit: 'HOURS') {
// Figure out the platforms to build on.
def platforms = getPlatforms()
assert !((platforms.size() > 1) && (OCK_FULL_URL != "")) : "Cannot specify full OCK URL and multiple platforms."
// Check whether the build has to be run multiple times in parallel.
def iter = (PARALLEL_ITERATIONS ?: "1").toInteger()
echo "Parallel iterations to be run: ${iter}"
def mapForParallel = [:]
currentBuild.description = ""
// Create jobs for each platform, as provided by user.
for (i = 0; i < iter; i++) {
for (platform in platforms) {
mapForParallel["${platform}: Iteration ${i}"] = run(platform.trim())
}
}
// Run said jobs in parallel.
parallel mapForParallel
}
}
}
}
}
}
}