forked from adoptium/installer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
439 lines (417 loc) · 16.2 KB
/
Jenkinsfile
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
/*
--------------------------------------------
buildArch RPM DEB Comments
--------------------------------------------
x86_64 x86_64 amd64
armv7l armv7hl armhf arm32
aarch64 aarch64 arm64 arm64
ppc64le ppc64le ppc64le
source src - only for SRPM and no need specify as option or target
s390x s390x s390x only for jdk8+
*/
env.NODE_LABEL = 'dockerBuild&&linux&&x64' // Default node and also used for build RedHat + Suse + Debian x64
env.PRODUCT = 'temurin'
class Types {
final static String JDK = 'Jdk'
final static String JRE = 'Jre'
final static List<String> ALL = [JDK, JRE]
static String displayName(TYPE, VERSION, ARCH, DISTRO) {
return "${TYPE.toLowerCase()}${VERSION} - ${ARCH} - ${DISTRO}"
}
}
pipeline {
agent {
label NODE_LABEL
}
options {
timeout(time: 2, unit: 'HOURS')
}
parameters {
choice(name: 'TYPE', choices: Types.ALL, description: 'Build JDK or JRE')
choice(name: 'VERSION', choices: ['8', '11', '17', '20'], description: 'Build for specific JDK VERSION')
choice(name: 'ARCH', choices: ['x86_64', 'armv7l', 'aarch64', 'ppc64le', 's390x', 'all'], description: 'Build for specific platform\n s390x not for VERSION 8\n')
choice(name: 'DISTRO', choices: ['all', 'Alpine', 'Debian', 'RedHat', 'Suse'], description: 'Build for specific Distro\n Select RPM builds for RedHat and Suse')
booleanParam(name: 'uploadPackage', defaultValue: false, description: 'Tick this box to upload the deb/rpm files (exclude src.rpm) to Artifactory for official release')
booleanParam(name: 'uploadSRCRPM', defaultValue: false, description: 'Tick this box to upload (src.rpm files) to Artifactory')
string(name: 'gitrepo', defaultValue: getCurrentRepoUrl(), description: 'Do not modify unless want to build from a specific gitrepo')
string(name: 'gitbranch', defaultValue: getCurrentBranch(), description: 'Do not change unless want to build on a specific branch from above gitrepo')
booleanParam(name: 'enableGpgSigning', defaultValue: true, description: 'Require GPG Signing')
booleanParam(name: 'enableDebug', defaultValue: false, description: 'Tick to enable --stacktrace for gradle build')
}
stages {
stage('Prepare Build') {
steps {
script {
currentBuild.displayName = Types.displayName(TYPE, VERSION, ARCH, DISTRO)
currentBuild.description = env.BUILD_USER_ID
sh('docker --version')
}
checkout(
[
$class: 'GitSCM',
branches: [[name: "$gitbranch"]],
extensions: [[$class: 'CleanBeforeCheckout', deleteUntrackedNestedRepositories: true]],
userRemoteConfigs: [[url: "$gitrepo"]]
]
)
dir('linux') {
stash name: 'installercode', includes: '**'
}
}
}
stage('BUILD')
{
parallel{
stage('Build Installer for Alpine') {
when {
beforeAgent true
anyOf {
expression { params.DISTRO == 'all' }
expression { params.DISTRO == 'Alpine' } // only trigger debian build
}
}
steps{
dir('linuxDebian') {
script {
jenkinsStepNonDeb("Alpine")
}
}
}
}
stage('Build Installer for Debian') {
when {
beforeAgent true
anyOf {
expression { params.DISTRO == 'all' }
expression { params.DISTRO == 'Debian' } // only trigger debian build
}
}
// specific jenkins agent will be assigned inside of jenkinsSepDeb() per ARCH
steps {
dir('linuxDebian') {
script {
jenkinsStepDeb()
}
}
}
}
stage('Build Installer for Redhat') {
when {
beforeAgent true
anyOf {
expression { params.DISTRO == 'all' }
expression { params.DISTRO == 'RedHat' } // only trigger redhat build
}
}
steps {
dir('linuxRedHat') {
script {
DISTRO = 'RedHat'
jenkinsStepNonDeb('RedHat')
}
}
}
}
stage('Build Installer for Suse') {
when {
beforeAgent true // do condition when before allocate to agent
anyOf {
expression { params.DISTRO == 'all' }
expression { params.DISTRO == 'Suse' } // only trigger suse build
}
}
steps {
dir('linuxSuse') {
script {
jenkinsStepNonDeb('Suse')
}
}
}
}
}
}
}
}
/*
* Common Functions
*/
// This makes it easier to run the builds from a different repository (for testing purposes) by default
private String getCurrentRepoUrl() {
return scm.getUserRemoteConfigs().first().getUrl() ?: 'https://github.com/adoptium/installer'
}
private String getCurrentBranch() {
return scm.branches.first().name ?: 'master'
}
// function only handle debian as DISTRO
def jenkinsStepDeb() {
def temurinVersion = "${TYPE.toLowerCase()} ${VERSION} - ${ARCH}"
echo "Installer Job for Temurin ${temurinVersion} - Debian"
//make sure this is an array not a string
def debArchAllList = []
// for one single ARCH add into array
debArchAllList.add("${ARCH}")
// when ARCH = all, rewrite list
if ("${ARCH}" == 'all') {
debArchAllList = ['x86_64', 'armv7l', 'aarch64', 'ppc64le', 's390x']
}
// remove s390x for JDK8 and JDK20
if ("${VERSION}" == '8' || "${VERSION}" == '20') {
debArchAllList.remove('s390x')
}
// remove armv7l for JDK20
if ("${VERSION}" == '20') {
debArchAllList.remove('armv7l')
}
debArchAllList.each { DebARCH ->
// special handle: no label x86_64 only x64 for debian agent
def debLabel = "${DebARCH}&&docker"
if ("${DebARCH}" == 'x86_64') {
debLabel = 'x64&&dockerBuild'
}
// reallocate jenkins agent per element in list
node("linux&&${debLabel}") {
setup('Debian', "${DebARCH}")
unstash 'installercode'
buildAndTest('Debian', "${DebARCH}")
if (params.uploadPackage.toBoolean()) {
echo "Upload artifacts for ${VERSION} - ${DebARCH} - Debian"
uploadArtifacts('Debian', "${DebARCH}")
}
}
}
}
// function handle both Alpine, RedHat and Suse as DISTRO
def jenkinsStepNonDeb(String DISTRO) {
echo "Installer Job for Temurin jdk ${VERSION} - ${ARCH} - ${DISTRO}"
setup("${DISTRO}", "${ARCH}")
unstash 'installercode'
buildAndTest("${DISTRO}", "${ARCH}")
if (params.uploadPackage.toBoolean()) {
echo "Upload artifacts for ${VERSION} - ${ARCH} - ${DISTRO}"
uploadArtifacts("${DISTRO}", "${ARCH}")
}
}
// common function regardless DISTRO
def setup(String DISTRO, String buildArch) {
cleanWs()
// Docker --mount option requires BuildKit
env.DOCKER_BUILDKIT = 1
env.COMPOSE_DOCKER_CLI_BUILD = 1
env._JAVA_OPTIONS = (buildArch == 'armv7l' && DISTRO == 'Debian') ? '' : '-Xmx4g'
}
// common function regardless DISTRO
def buildAndTest(String DISTRO, String buildArch) {
try {
if (DISTRO != "Debian") { // for RPM based: RedHat / Suse / Alpine
def privateKey = 'adoptium-artifactory-gpg-key'
if (DISTRO == "Alpine") {
privateKey = 'adoptium-artifactory-rsa-key'
}
if (params.enableGpgSigning) {
// Use Adoptium GPG key for signing
withCredentials([file(credentialsId: privateKey, variable: 'GPG_KEY')]) {
buildCli(DISTRO, buildArch, GPG_KEY)
}
} else {
buildCli(DISTRO, buildArch)
}
} else {
def gBuildTask = (buildArch == 'x86_64') ? "package${TYPE}${DISTRO} check${TYPE}${DISTRO}" : "package${TYPE}${DISTRO}"
def debArchList = [
'x86_64' : 'amd64',
'armv7l': 'armhf',
'aarch64': 'arm64',
'ppc64le': 'ppc64el',
's390x' : 's390x'
]
def buildCli = "./gradlew ${gBuildTask} --parallel -PPRODUCT=${env.PRODUCT} -PPRODUCT_VERSION=${VERSION} -PARCH=${debArchList[buildArch]}"
buildCli = params.enableDebug.toBoolean() ? buildCli + ' --stacktrace' : buildCli
sh("$buildCli")
}
} catch (Exception ex) {
echo 'Exception in buildAndTest: ' + ex
currentBuild.result = 'FAILURE' // set the whole pipeline 'red' if build or test fail. Do not use "error" that will not call "finally"
} finally {
// should not allow empty archive, otherwise nothing created in the previous step: package and test result( not needed )
archiveArtifacts artifacts: '**/build/ospackage/*,**/build/reports/**,**/packageTest/dependencies/deb/*', onlyIfSuccessful:false, allowEmptyArchive: false
}
}
private void buildCli(String DISTRO, String buildArch, String GPG_KEY = null) {
def buildCli = "./gradlew package${TYPE}${DISTRO} check${TYPE}${DISTRO} --parallel -PPRODUCT=${env.PRODUCT} -PPRODUCT_VERSION=${VERSION} -PARCH=${buildArch}"
if (GPG_KEY) {
buildCli += " -PGPG_KEY=${GPG_KEY}"
}
if (params.enableDebug.toBoolean()) {
buildCli += " --stacktrace"
}
sh(buildCli)
}
def uploadArtifacts(String DISTRO, String buildArch) {
switch(DISTRO) {
case "Debian":
uploadDebArtifacts(buildArch)
break
case "Alpine":
uploadAlpineArtifacts(buildArch)
break
default:
uploadRpmArtifacts(DISTRO,buildArch)
break
}
}
def uploadAlpineArtifacts(String buildArch) {
// currently only support x64 as buildArch
rtUpload ( //artifactory plugin
serverId: 'adoptium.jfrog.io',
failNoOp: true,
spec: """{
"files": [
{
"pattern": "**/build/ospackage/temurin-*j*.apk",
"target": "apk/alpine/main/${buildArch}/"
},
{
"pattern": "**/build/ospackage/temurin-*src*.apk",
"target": "apk/alpine/main/${buildArch}/"
}
]
}""",
)
}
def uploadDebArtifacts(String buildArch) {
def debArchList = [
'x86_64' : 'amd64',
'armv7l': 'armhf',
'aarch64': 'arm64',
'ppc64le': 'ppc64el',
's390x' : 's390x'
]
// if VERSION is 8 or 20 remove s390x from the list
if (VERSION == '8' || VERSION == '20') {
debArchList.remove('s390x')
}
// if VERSION is 20 remove armv7l from the list
if (VERSION == '20') {
debArchList.remove('armv7l')
}
/*
Debian/Ubuntu 10.0 11.0 16.04 20.04 22.04 22.10
add more into list when available for release
also update linux/{jdk,jre}/debian/main/packing/build.sh
*/
def deb_versions = [
"bookworm", // Debian/12
"bullseye", // Debian/11
"buster", // Debian/10
"kinetic", // Ubuntu/22.10
"jammy", // Ubuntu/22.04 (LTS)
"focal", // Ubuntu/20.04 (LTS)
"bionic", // Ubuntu/18.04 (LTS)
]
def distro_list = ''
deb_versions.each { deb_version ->
// Creates list like deb.distribution=stretch;deb.distribution=buster;
distro_list += "deb.distribution=${deb_version};"
}
for (int i = 0; i < 5; i++) { // loop 5 times at most
echo "Prepare for ${debArchList[buildArch]}.deb"
if(findFiles(glob: "**/build/ospackage/temurin-*${debArchList[buildArch]}.deb").length == 0) {
/*
workaround for error when upload to artifactory: No files were affected in the upload process
might be caused by slow archive done by jenkins
*/
sleep 2
} else {
rtUpload( //artifactory plugin
serverId: 'adoptium.jfrog.io',
failNoOp: true,
spec: """{
"files": [
{
"pattern": "**/build/ospackage/temurin-*${debArchList[buildArch]}.deb",
"target": "deb/pool/main/t/temurin-${VERSION}/",
"props": "${distro_list}deb.component=main;deb.architecture=${debArchList[buildArch]}"
}
]
}""",
)
break
}
}
}
def uploadRpmArtifacts(String DISTRO, String rpmArch) {
def distro_Package = [
'redhat' : [
'rpm/centos/7',
'rpm/rocky/8',
'rpm/rhel/7',
'rpm/rhel/8',
'rpm/rhel/9',
'rpm/fedora/35',
'rpm/fedora/36',
'rpm/fedora/37',
'rpm/fedora/38',
'rpm/oraclelinux/7',
'rpm/oraclelinux/8',
'rpm/amazonlinux/2'
],
'suse' : [
'rpm/opensuse/15.3',
'rpm/opensuse/15.4',
'rpm/sles/12',
'rpm/sles/15'
]
]
def packageDirs = distro_Package[DISTRO.toLowerCase()]
def rpmArchList=[
'x86_64' : 'x86_64',
'armv7hl': 'armv7hl',
'aarch64': 'aarch64',
'ppc64le': 'ppc64le',
's390x' : 's390x'
]
// if VERSION is 8 or 20 remove s390x from the list
if (VERSION == '8' || VERSION == '20') {
rpmArchList.remove('s390x')
}
// if VERSION is 20 remove armv7hl from the list
if (VERSION == '20') {
rpmArchList.remove('armv7hl')
}
if ("${rpmArch}" != 'all') {
// when only build and upload one arch, reset
rpmArchList = [("${rpmArch}" as String): "${rpmArchList[rpmArch]}"]
}
// Enable upload src.rpm
if ( params.uploadSRCRPM.toBoolean() || params.DISTRO == 'all' ) {
rpmArchList.put('source', 'src')
}
packageDirs.each { packageDir ->
rpmArchList.each { entry ->
for (int i = 0; i < 5; i++) { // loop 5 times at most
echo "Prepare for ${entry.value}.rpm"
if(findFiles(glob: "**/build/ospackage/*.${entry.value}.rpm").length == 0) {
/*
workaround for error when upload to artifactory: No files were affected in the upload process
might be caused by slow archive done by jenkins
*/
sleep 2
} else {
rtUpload(
serverId: 'adoptium.jfrog.io',
failNoOp: true,
spec: """{
"files": [
{
"pattern": "**/build/ospackage/*.${entry.value}.rpm",
"target": "${packageDir}/${entry.key}/Packages/"
}
]
}"""
)
break
}
}
}
}
}