-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile.release
756 lines (686 loc) · 32.5 KB
/
Jenkinsfile.release
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
#!groovy
/**
* This program and the accompanying materials are made available under the terms of the
* Eclipse Public License v2.0 which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright IBM Corporation 2018, 2019
*/
node('zowe-jenkins-agent-dind-wdc') {
def lib = library("jenkins-library@users/tom/releasepipelinechanges").org.zowe.jenkins_shared_library
def ZOWE_RELEASE_REPOSITORY = 'libs-release-local'
def ZOWE_RELEASE_PATH = '/org/zowe'
def ZOWE_RELEASE_FILEPATTERN = "zowe-*.pax"
def ZOWE_RELEASE_SMPE_PAX_FILEPATTERN = "zowe-smpe-*.zip"
def ZOWE_RELEASE_SMPE_PTF_PROMOTE_FILEPATTERN = "smpe-promote-*.tar"
def ZOWE_RELEASE_DOCKER_AMD64_FILEPATTERN = "server-bundle.amd64-*.tar"
def ZOWE_RELEASE_DOCKER_AMD64_SOURCE_FILEPATTERN = "server-bundle.sources.amd64-*.tar"
def ZOWE_RELEASE_DOCKER_S390X_FILEPATTERN = "server-bundle.s390x-*.tar"
def ZOWE_RELEASE_DOCKER_S390X_SOURCE_FILEPATTERN = "server-bundle.sources.s390x-*.tar"
def ZOWE_RELEASE_CONTAINERIZATION_FILEPATTERN = "zowe-containerization-*.zip"
def ZOWE_RELEASE_CLI_CORE_FILEPATTERN = "zowe-cli-package-1*.zip"
def ZOWE_RELEASE_CLI_PLUGINS_FILEPATTERN = "zowe-cli-plugins-1*.zip"
def ZOWE_INSTALL_PACKAGING_REPO = 'zowe/zowe-install-packaging'
def pipeline = lib.pipelines.generic.GenericPipeline.new(this)
def github = lib.scm.GitHub.new(this)
def isFormalRelease = false
def releaseFilePath
def releaseArtifacts = readJSON(text:'{}')
def publishFilePath
def smpePtfPromoteTarPath
pipeline.admins.add("jackjia", "markackert")
// we have extra parameters for the pipeline
pipeline.addBuildParameters(
string(
name: 'ZOWE_BUILD_REPOSITORY',
description: 'Zowe successful build repository',
defaultValue: 'libs-snapshot-local',
trim: true,
required: true
),
// the purpose of this variable is Artifactory sometimes messed up build/artifact association.
// when search by build number, some artifacts from other builds may show up.
// this can narrow down the path to find the artifacts
string(
name: 'ZOWE_BUILD_PATH',
description: 'Zowe successful build path. For example, "org/zowe/1.12.0-SNAPSHOT".',
defaultValue: '*',
trim: true,
required: true
),
string(
name: 'ZOWE_BUILD_NAME',
description: 'Zowe successful build name',
defaultValue: 'zowe-install-packaging :: master',
trim: true,
required: true
),
string(
name: 'ZOWE_BUILD_NUMBER',
description: 'Zowe successful build number',
defaultValue: '',
trim: true,
required: true
),
string(
name: 'ZOWE_CLI_BUILD_REPOSITORY',
description: 'Zowe CLI successful build repository',
defaultValue: 'libs-release-local',
trim: true,
required: true
),
string(
name: 'ZOWE_CLI_BUILD_PATH',
description: 'Zowe CLI successful build path. For example, "org/zowe/cli/*".',
defaultValue: 'org/zowe/cli/*',
trim: true,
required: true
),
string(
name: 'ZOWE_CLI_BUILD_NAME',
description: 'Zowe CLI successful build name',
defaultValue: '',
trim: true,
required: false
),
string(
name: 'ZOWE_CLI_BUILD_NUMBER',
description: 'REQUIRED if ZOWE_CLI_BUILD_RC_PATH is empty. Zowe CLI successful build number',
defaultValue: '',
trim: true,
required: false
),
string(
name: 'ZOWE_RELEASE_VERSION',
description: 'REQUIRED. Zowe release version without prefix v. For example, 0.9.0',
defaultValue: '',
trim: true,
required: true
)
)
pipeline.setup(
packageName: 'org.zowe',
github: [
email : lib.Constants.DEFAULT_GITHUB_ROBOT_EMAIL,
usernamePasswordCredential : lib.Constants.DEFAULT_GITHUB_ROBOT_CREDENTIAL,
],
artifactory: [
url : lib.Constants.DEFAULT_LFJ_ARTIFACTORY_URL,
usernamePasswordCredential : lib.Constants.DEFAULT_LFJ_ARTIFACTORY_ROBOT_CREDENTIAL,
]
)
pipeline.build(
name : "Validate",
timeout : [time: 5, unit: 'MINUTES'],
isSkippable : true,
operation : {
if (!params.ZOWE_BUILD_NAME) {
error "ZOWE_BUILD_NAME is required to promote build."
}
if (!params.ZOWE_BUILD_NUMBER) {
error "ZOWE_BUILD_NUMBER is required to promote build."
}
// if (!params.ZOWE_CLI_BUILD_NAME) {
// error "ZOWE_CLI_BUILD_NAME is required to promote build."
// }
// if (!params.ZOWE_CLI_BUILD_NUMBER) {
// error "ZOWE_CLI_BUILD_NUMBER is required to promote build."
// }
if (!params.ZOWE_RELEASE_VERSION) {
error "ZOWE_RELEASE_VERSION is required to promote build."
}
echo "Checking if ${params.ZOWE_RELEASE_VERSION} is a valid semantic version ..."
// validate release version scheme
// thanks semver/semver, this regular expression comes from
// https://github.com/semver/semver/issues/232#issuecomment-405596809
if (!(params.ZOWE_RELEASE_VERSION ==~ /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/)) {
error "${params.ZOWE_RELEASE_VERSION} is not a valid semantic version."
}
if (params.ZOWE_RELEASE_VERSION ==~ /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/) {
isFormalRelease = true
echo ">>>> Version ${params.ZOWE_RELEASE_VERSION} is considered as a FORMAL RELEASE."
} else {
echo ">>>> Version ${params.ZOWE_RELEASE_VERSION} is NOT considered as a FORMAL RELEASE."
}
// this is the target Artifactory path will be released to
releaseFilePath = "${ZOWE_RELEASE_REPOSITORY}${ZOWE_RELEASE_PATH}/${params.ZOWE_RELEASE_VERSION}".toString()
// check artifactory release path
echo "Checking if ${params.ZOWE_RELEASE_VERSION} already exists in Artifactory ..."
def versionOnArtifactory
try {
versionOnArtifactory = pipeline.artifactory.getArtifact(releaseFilePath + "/*")
} catch (e) {
// ignore errors
}
if (versionOnArtifactory && versionOnArtifactory.path) {
error "Zowe version ${params.ZOWE_RELEASE_VERSION} already exists (${releaseFilePath})"
} else {
echo ">>>> Target artifactory folder ${releaseFilePath} doesn't exist, may proceed."
}
// check if tag already exists
github.cloneRepository([
email : lib.Constants.DEFAULT_GITHUB_ROBOT_EMAIL,
usernamePasswordCredential : lib.Constants.DEFAULT_GITHUB_ROBOT_CREDENTIAL,
repository : ZOWE_INSTALL_PACKAGING_REPO,
folder : '.tag',
branch : 'master'
])
if (github.tagExistsRemote("v${params.ZOWE_RELEASE_VERSION}")) {
error "Repository tag v${params.ZOWE_RELEASE_VERSION} already exists."
} else {
echo ">>>> Repository tag v${params.ZOWE_RELEASE_VERSION} doesn't exist, may proceed."
}
// find the Zowe build number will be promoted
releaseArtifacts['zowe'] = [:]
releaseArtifacts['zowe']['target'] = "zowe-${params.ZOWE_RELEASE_VERSION}.pax".toString()
releaseArtifacts['zowe']['buildName'] = params.ZOWE_BUILD_NAME
releaseArtifacts['zowe']['buildNumber'] = params.ZOWE_BUILD_NUMBER
// get zowe build source artifact
releaseArtifacts['zowe']['source'] = pipeline.artifactory.getArtifact([
'pattern' : "${params.ZOWE_BUILD_REPOSITORY}/${params.ZOWE_BUILD_PATH}/${ZOWE_RELEASE_FILEPATTERN}",
'build-name' : releaseArtifacts['zowe']['buildName'],
'build-number' : releaseArtifacts['zowe']['buildNumber']
])
echo ">>> Found Zowe build ${releaseArtifacts['zowe']['source']['path']}."
// try to get Zowe build commit hash
def zoweBuildInfo = pipeline.artifactory.getBuildInfo(
releaseArtifacts['zowe']['buildName'],
releaseArtifacts['zowe']['buildNumber'],
"zowe-install-packaging"
)
releaseArtifacts['zowe']['revision'] = (zoweBuildInfo && zoweBuildInfo['vcsRevision']) || (releaseArtifacts['zowe']['source'] && releaseArtifacts['zowe']['source']['vcs.revision'])
if (!("${releaseArtifacts['zowe']['revision']}" ==~ /^[0-9a-fA-F]{40}$/)) { // if it's a SHA-1 commit hash
error "Cannot extract git revision from build \"${releaseArtifacts['zowe']['buildName']}/${releaseArtifacts['zowe']['buildNumber']}\""
}
echo ">>>> Build ${releaseArtifacts['zowe']['buildName']}/${releaseArtifacts['zowe']['buildNumber']} commit hash is ${releaseArtifacts['zowe']['revision']}, may proceed."
// get SMP/e build
try {
def smpeTarSource = pipeline.artifactory.getArtifact([
'pattern' : "${params.ZOWE_BUILD_REPOSITORY}/${params.ZOWE_BUILD_PATH}/${ZOWE_RELEASE_SMPE_PAX_FILEPATTERN}",
'build-name' : releaseArtifacts['zowe']['buildName'],
'build-number' : releaseArtifacts['zowe']['buildNumber']
])
if (smpeTarSource['path']) {
echo ">>> Found SMP/e build ${smpeTarSource['path']}."
def FMID = smpeTarSource['path'].split('/').last().split('-').first()
releaseArtifacts['smpe-zip'] = [:]
releaseArtifacts['smpe-zip']['source'] = smpeTarSource
releaseArtifacts['smpe-zip']['target'] = "zowe-smpe-package-${params.ZOWE_RELEASE_VERSION}.zip".toString()
}
try {
def smpePtfPromote = pipeline.artifactory.getArtifact([
'pattern' : "${params.ZOWE_BUILD_REPOSITORY}/${params.ZOWE_BUILD_PATH}/${ZOWE_RELEASE_SMPE_PTF_PROMOTE_FILEPATTERN}",
'build-name' : releaseArtifacts['zowe']['buildName'],
'build-number' : releaseArtifacts['zowe']['buildNumber']
])
echo ">>> Found SMP/e promote tar ${smpePtfPromote['path']}."
smpePtfPromoteTarPath = smpePtfPromote['path']
} catch (e2) {
echo ">>> no SMP/e promote tar found in the build, throwing error and exit"
error "no SMP/e promote tar found in the build"
}
} catch (e1) {
echo ">>> no SMP/e zip found in the build, throwing error and exit"
error "no SMP/e zip found in the build"
}
// get Docker images - amd64
try {
def dockerImageAmd64 = pipeline.artifactory.getArtifact([
'pattern' : "${params.ZOWE_BUILD_REPOSITORY}/${params.ZOWE_BUILD_PATH}/${ZOWE_RELEASE_DOCKER_AMD64_FILEPATTERN}",
'build-name' : releaseArtifacts['zowe']['buildName'],
'build-number' : releaseArtifacts['zowe']['buildNumber']
])
if (dockerImageAmd64['path']) {
echo ">>> Found Docker image amd64 version ${dockerImageAmd64['path']}."
def FMID = dockerImageAmd64['path'].split('/').last().split('-').first()
releaseArtifacts['docker-amd64'] = [:]
releaseArtifacts['docker-amd64']['source'] = dockerImageAmd64
releaseArtifacts['docker-amd64']['target'] = "server-bundle.amd64-${params.ZOWE_RELEASE_VERSION}.tar".toString()
}
} catch (e1) {
echo ">>> no Docker image amd64 version found in the build."
}
// get Docker images with sources - amd64
try {
def dockerImageSourcesAmd64 = pipeline.artifactory.getArtifact([
'pattern' : "${params.ZOWE_BUILD_REPOSITORY}/${params.ZOWE_BUILD_PATH}/${ZOWE_RELEASE_DOCKER_AMD64_SOURCE_FILEPATTERN}",
'build-name' : releaseArtifacts['zowe']['buildName'],
'build-number' : releaseArtifacts['zowe']['buildNumber']
])
if (dockerImageSourcesAmd64['path']) {
echo ">>> Found Docker image amd64 sources version ${dockerImageSourcesAmd64['path']}."
def FMID = dockerImageSourcesAmd64['path'].split('/').last().split('-').first()
releaseArtifacts['docker-amd64-sources'] = [:]
releaseArtifacts['docker-amd64-sources']['source'] = dockerImageSourcesAmd64
releaseArtifacts['docker-amd64-sources']['target'] = "server-bundle.sources.amd64-${params.ZOWE_RELEASE_VERSION}.tar".toString()
}
} catch (e1) {
echo ">>> no Docker image amd64 sources version found in the build."
}
// get Docker images - s390x
try {
def dockerImageS390x = pipeline.artifactory.getArtifact([
'pattern' : "${params.ZOWE_BUILD_REPOSITORY}/${params.ZOWE_BUILD_PATH}/${ZOWE_RELEASE_DOCKER_S390X_FILEPATTERN}",
'build-name' : releaseArtifacts['zowe']['buildName'],
'build-number' : releaseArtifacts['zowe']['buildNumber']
])
if (dockerImageS390x['path']) {
echo ">>> Found Docker image s390x version ${dockerImageS390x['path']}."
def FMID = dockerImageS390x['path'].split('/').last().split('-').first()
releaseArtifacts['docker-s390x'] = [:]
releaseArtifacts['docker-s390x']['source'] = dockerImageS390x
releaseArtifacts['docker-s390x']['target'] = "server-bundle.s390x-${params.ZOWE_RELEASE_VERSION}.tar".toString()
}
} catch (e1) {
echo ">>> no Docker image s390x version found in the build."
}
// get Docker images with sources - s390x
try {
def dockerImageSourcesS390x = pipeline.artifactory.getArtifact([
'pattern' : "${params.ZOWE_BUILD_REPOSITORY}/${params.ZOWE_BUILD_PATH}/${ZOWE_RELEASE_DOCKER_S390X_SOURCE_FILEPATTERN}",
'build-name' : releaseArtifacts['zowe']['buildName'],
'build-number' : releaseArtifacts['zowe']['buildNumber']
])
if (dockerImageSourcesS390x['path']) {
echo ">>> Found Docker image s390x sources version ${dockerImageSourcesS390x['path']}."
def FMID = dockerImageSourcesS390x['path'].split('/').last().split('-').first()
releaseArtifacts['docker-s390x-sources'] = [:]
releaseArtifacts['docker-s390x-sources']['source'] = dockerImageSourcesS390x
releaseArtifacts['docker-s390x-sources']['target'] = "server-bundle.sources.s390x-${params.ZOWE_RELEASE_VERSION}.tar".toString()
}
} catch (e1) {
echo ">>> no Docker image s390x sources version found in the build."
}
// get containerization
try {
def containerization = pipeline.artifactory.getArtifact([
'pattern' : "${params.ZOWE_BUILD_REPOSITORY}/${params.ZOWE_BUILD_PATH}/${ZOWE_RELEASE_CONTAINERIZATION_FILEPATTERN}",
'build-name' : releaseArtifacts['zowe']['buildName'],
'build-number' : releaseArtifacts['zowe']['buildNumber']
])
if (containerization['path']) {
echo ">>> Found containerization version ${containerization['path']}."
def FMID = containerization['path'].split('/').last().split('-').first()
releaseArtifacts['containerization'] = [:]
releaseArtifacts['containerization']['source'] = containerization
releaseArtifacts['containerization']['target'] = "zowe-containerization-${params.ZOWE_RELEASE_VERSION}.zip".toString()
}
} catch (e1) {
echo ">>> no containerization version found in the build."
}
// find the Zowe CLI build number will be promoted
releaseArtifacts['cli'] = [:]
releaseArtifacts['cli']['target'] = "zowe-cli-package-${params.ZOWE_RELEASE_VERSION}.zip".toString()
releaseArtifacts['cli-plugins'] = [:]
releaseArtifacts['cli-plugins']['target'] = "zowe-cli-plugins-${params.ZOWE_RELEASE_VERSION}.zip".toString()
// CLI Core
releaseArtifacts['cli']['buildName'] = params.ZOWE_CLI_BUILD_NAME
releaseArtifacts['cli']['buildNumber'] = params.ZOWE_CLI_BUILD_NUMBER
// CLI Plugins
releaseArtifacts['cli-plugins']['buildName'] = params.ZOWE_CLI_BUILD_NAME
releaseArtifacts['cli-plugins']['buildNumber'] = params.ZOWE_CLI_BUILD_NUMBER
// get CLI CORE build source artifact
releaseArtifacts['cli']['source'] = pipeline.artifactory.getArtifact([
'pattern' : "${params.ZOWE_CLI_BUILD_REPOSITORY}/${params.ZOWE_CLI_BUILD_PATH}/${ZOWE_RELEASE_CLI_CORE_FILEPATTERN}",
// 'build-name' : releaseArtifacts['cli']['buildName'], // we no longer rely on jenkins to find artifacts
// 'build-number' : releaseArtifacts['cli']['buildNumber'] // we no longer rely on jenkins to find artifacts
])
echo ">>> Found Zowe CLI build ${releaseArtifacts['cli']['source']['path']}."
// get CLI PLUGINS builds source artifact
releaseArtifacts['cli-plugins']['source'] = pipeline.artifactory.getArtifact([
'pattern' : "${params.ZOWE_CLI_BUILD_REPOSITORY}/${params.ZOWE_CLI_BUILD_PATH}/${ZOWE_RELEASE_CLI_PLUGINS_FILEPATTERN}",
// 'build-name' : releaseArtifacts['cli-plugins']['buildName'], // we no longer rely on jenkins to find artifacts
// 'build-number' : releaseArtifacts['cli-plugins']['buildNumber'] // we no longer rely on jenkins to find artifacts
])
echo ">>> Found Zowe CLI Plugins ${releaseArtifacts['cli-plugins']['source']['path']}."
// try to get Zowe CLI CORE build commit hash
if (releaseArtifacts['cli']['buildName'] && releaseArtifacts['cli']['buildNumber']) {
def cliBuildInfo = pipeline.artifactory.getBuildInfo(
releaseArtifacts['cli']['buildName'],
releaseArtifacts['cli']['buildNumber'],
'zowe-cli'
)
}
// releaseArtifacts['cli']['revision'] = cliBuildInfo && cliBuildInfo['vcsRevision']
// if (!("${releaseArtifacts['cli']['revision']}" ==~ /^[0-9a-fA-F]{40}$/)) { // if it's a SHA-1 commit hash
// error "Cannot extract git revision from build \"${releaseArtifacts['cli']['buildName']}/${releaseArtifacts['cli']['buildNumber']}\""
// }
// echo ">>>> Build ${releaseArtifacts['cli']['buildName']}/${releaseArtifacts['cli']['buildNumber']} commit hash is ${releaseArtifacts['cli']['revision']}, may proceed."
// try to get Zowe CLI Plugins build commit hash
if (releaseArtifacts['cli-plugins']['buildName'] && releaseArtifacts['cli-plugins']['buildNumber']) {
def cliPluginsBuildInfo = pipeline.artifactory.getBuildInfo(
releaseArtifacts['cli-plugins']['buildName'],
releaseArtifacts['cli-plugins']['buildNumber'],
'zowe-cli'
)
}
// releaseArtifacts['cli-plugins']['revision'] = cliPluginsBuildInfo && cliPluginsBuildInfo['vcsRevision']
// if (!("${releaseArtifacts['cli-plugins']['revision']}" ==~ /^[0-9a-fA-F]{40}$/)) { // if it's a SHA-1 commit hash
// error "Cannot extract git revision from build \"${releaseArtifacts['cli-plugins']['buildName']}/${releaseArtifacts['cli-plugins']['buildNumber']}\""
// }
// echo ">>>> Build ${releaseArtifacts['cli-plugins']['buildName']}/${releaseArtifacts['cli-plugins']['buildNumber']} commit hash is ${releaseArtifacts['cli-plugins']['revision']}, may proceed."
}
)
pipeline.createStage(
name : "Generate Source Build",
isSkippable : true,
shouldExecute : {
return isFormalRelease
},
stage : {
// files should be downloaded to .release/source_zip
withCredentials([
usernamePassword(
credentialsId: lib.Constants.DEFAULT_GITHUB_ROBOT_CREDENTIAL,
passwordVariable: 'GITHUB_PASSWORD',
usernameVariable: 'GITHUB_USERNAME'
)
]) {
sh './.dependency/prepare_source_zip.sh'
}
// zip files
zip dir: '.release/source_zip', glob: '', zipFile: ".release/zowe_sources-${params.ZOWE_RELEASE_VERSION}.zip"
},
timeout: [time: 10, unit: 'MINUTES']
)
pipeline.createStage(
name : "Promote",
isSkippable : true,
stage : {
// debug show releaseArtifacts
writeJSON file: '.tmp-release-artifacts.json', json: releaseArtifacts, pretty: 2
sh "set +x\n" +
"echo All artifacts will be promoted:\n" +
"echo ===============================================\n" +
"cat .tmp-release-artifacts.json\n" +
"echo\n" +
"echo ===============================================\n"
releaseArtifacts.each { artifact, info ->
echo ">>> Promoting ${artifact} ..."
pipeline.artifactory.promote([
'source': info['source'],
'targetPath': releaseFilePath,
'targetName': info['target']
])
}
},
timeout: [time: 10, unit: 'MINUTES']
)
pipeline.createStage(
name : "Download",
isSkippable : true,
stage : {
// download all promoted artifacts into .release folder
sh 'mkdir -p .release'
def downloadArtifacts = readJSON(text:'{"files":[]}')
def expected = releaseArtifacts.size()
releaseArtifacts.each { artifact, info ->
downloadArtifacts['files'].push([
"pattern" : "${releaseFilePath}/${info['target']}".toString(),
"target" : '.release/',
"flat" : 'true'
])
}
// debug show downloadArtifacts
writeJSON file: '.tmp-download-artifacts.json', json: downloadArtifacts, pretty: 2
sh "set +x\n" +
"echo All promoted artifacts:\n" +
"echo ===============================================\n" +
"cat .tmp-download-artifacts.json\n" +
"echo\n" +
"echo ==============================================="
echo ">>> Downloading all promoted artifacts ..."
pipeline.artifactory.download([
'spec' : '.tmp-download-artifacts.json',
'expected' : expected
])
},
timeout: [time: 20, unit: 'MINUTES']
)
pipeline.createStage(
name : "Sign",
isSkippable : true,
shouldExecute : {
return isFormalRelease
},
stage : {
def signing = lib.package.Signing.new(this)
def uploadArtifacts = readJSON(text:'{"files":[]}')
// pload zowe_sources
uploadArtifacts['files'].push([
"pattern" : '.release/zowe_sources-*.zip',
"target" : releaseFilePath + '/'
])
releaseArtifacts.each { artifact, info ->
echo ">>> Signing ${info['target']} ..."
signing.sign(".release/${info['target']}")
uploadArtifacts['files'].push([
"pattern" : ".release/${info['target']}.asc".toString(),
"target" : releaseFilePath + '/'
])
echo ">>> Generate hash of ${info['target']} ..."
signing.hash(".release/${info['target']}")
uploadArtifacts['files'].push([
"pattern" : ".release/${info['target']}.sha512".toString(),
"target" : releaseFilePath + '/'
])
}
// write code-signing-key-info.json
def signingKeyId = signing.getSigningKey()
sh "curl -o .release/code-signing-key-info.json https://raw.githubusercontent.com/zowe/zowe-install-packaging/master/signing_keys/${signingKeyId}.json"
if (!fileExists('.release/code-signing-key-info.json')) {
error "Failed to download code signing key info json"
}
uploadArtifacts['files'].push([
"pattern" : '.release/code-signing-key-info.json',
"target" : releaseFilePath + '/'
])
// write version, no need to upload to Artifactory
writeFile file: '.release/version', text: params.ZOWE_RELEASE_VERSION
// debug show uploadArtifacts
writeJSON file: '.tmp-upload-artifacts.json', json: uploadArtifacts, pretty: 2
sh "set +x\n" +
"echo All signing results:\n" +
"echo ===============================================\n" +
"cat .tmp-upload-artifacts.json\n" +
"echo\n" +
"echo ===============================================\n"
echo ">>> Uploading signing results ..."
pipeline.artifactory.upload([spec: '.tmp-upload-artifacts.json'])
},
timeout: [time: 20, unit: 'MINUTES']
)
pipeline.createStage(
name : "Tag Branch",
isSkippable : true,
shouldExecute : {
return isFormalRelease && releaseArtifacts['zowe'] && releaseArtifacts['zowe']['revision']
},
stage : {
echo ">>> Tagging ${releaseArtifacts['zowe']['revision']} as v${params.ZOWE_RELEASE_VERSION} ..."
github.cloneRepository([
email : lib.Constants.DEFAULT_GITHUB_ROBOT_EMAIL,
usernamePasswordCredential : lib.Constants.DEFAULT_GITHUB_ROBOT_CREDENTIAL,
repository : ZOWE_INSTALL_PACKAGING_REPO,
folder : '.tag',
branch : 'master'
])
github.command('git checkout ' + releaseArtifacts['zowe']['revision'])
def commit = github.getLastCommitHash()
if (commit != releaseArtifacts['zowe']['revision']) {
error "Failed to checkout ${releaseArtifacts['zowe']['revision']} for tagging."
}
github.tag("v${params.ZOWE_RELEASE_VERSION}")
},
timeout: [time: 10, unit: 'MINUTES']
)
pipeline.createStage(
name : "Promote PTF",
isSkippable : true,
shouldExecute : {
return isFormalRelease && releaseArtifacts['zowe'] && releaseArtifacts['zowe']['revision'] && smpePtfPromoteTarPath
},
stage : {
def gitPromotePtf = lib.scm.GitHub.new(this)
def pathPromotePtfGit = '.promote-ptf'
def pathPromotePtfTmp = '.release/promote-ptf'
// clone staging branch
gitPromotePtf.cloneRepository([
email : lib.Constants.DEFAULT_GITHUB_ROBOT_EMAIL,
usernamePasswordCredential : lib.Constants.DEFAULT_GITHUB_ROBOT_CREDENTIAL,
repository : ZOWE_INSTALL_PACKAGING_REPO,
folder : pathPromotePtfGit,
branch : 'staging'
])
// checkout new branch for PR
gitPromotePtf.checkout("users/robot/promote-ptf-from-${currentBuild.number}", true)
// download smpe-promote zip
pipeline.artifactory.download([
'specContent' : ([
"{\"files\":[{",
"\"pattern\":\"${smpePtfPromoteTarPath}\",",
"\"target\":\"${pathPromotePtfTmp}/smpe-promote.tar\",",
"\"flat\":\"true\"",
"}]}",
].join("")),
'expected' : 1
])
// run smpe-promote.sh
def pwd = sh(script: 'pwd', returnStdout: true).trim()
dir("${pathPromotePtfGit}/smpe/bld") {
// use current branch version smpe-promote.sh
sh "cp smpe-promote.sh smpe-promote.sh.bak && cp \"${pwd}/smpe/bld/smpe-promote.sh\" ."
sh "./smpe-promote.sh -d -p \"${pwd}/${pathPromotePtfTmp}/smpe-promote.tar\""
sh "mv smpe-promote.sh.bak smpe-promote.sh"
// revert smpe-promote.sh, don't commit in this PR
}
// show change status
echo gitPromotePtf.command('git status')
// commit all changes
gitPromotePtf.commit("Promote PTF after release v${params.ZOWE_RELEASE_VERSION}")
// push before creating PR
gitPromotePtf.push()
// create PR
def pullRequestId = gitPromotePtf.createPullRequest('staging', 'Automatically Promote PTF after release by zowe robot')
echo "Pull request #${pullRequestId} is created."
},
timeout: [time: 10, unit: 'MINUTES']
)
pipeline.createStage(
name : "Publish Docker Image",
isSkippable : true,
displayTimestamp : true,
timeout : [time: 120, unit: 'MINUTES'],
shouldExecute : {
return isFormalRelease && (releaseArtifacts['docker-amd64'] || releaseArtifacts['docker-s390x'])
},
stage : {
withCredentials([usernamePassword(
credentialsId: 'ZoweDockerhub',
usernameVariable: 'USERNAME',
passwordVariable: 'PASSWORD'
)]) {
def publishCommands = "docker login -u \"${USERNAME}\" -p \"${PASSWORD}\"\n"
def manifestAmends = ""
def manifestSourceAmends = ""
// load images
if (releaseArtifacts['docker-amd64']) {
// the image in tar should always be ompzowe/server-bundle:amd64
sh "docker load --input .release/server-bundle.amd64-*.tar"
publishCommands += "docker push ompzowe/server-bundle:amd64\n"
manifestAmends += " --amend ompzowe/server-bundle:amd64"
}
if (releaseArtifacts['docker-amd64-sources']) {
// the image in tar should always be ompzowe/server-bundle:amd64-sources
sh "docker load --input .release/server-bundle.sources.amd64-*.tar"
publishCommands += "docker push ompzowe/server-bundle:amd64-sources\n"
manifestSourceAmends += " --amend ompzowe/server-bundle:amd64-sources"
}
if (releaseArtifacts['docker-s390x']) {
// the image in tar should always be ompzowe/server-bundle:s390x
sh "docker load --input .release/server-bundle.s390x-*.tar"
publishCommands += "docker push ompzowe/server-bundle:s390x\n"
manifestAmends += " --amend ompzowe/server-bundle:s390x"
}
if (releaseArtifacts['docker-s390x-sources']) {
// the image in tar should always be ompzowe/server-bundle:amd64-sources
sh "docker load --input .release/server-bundle.sources.s390x-*.tar"
publishCommands += "docker push ompzowe/server-bundle:s390x-sources\n"
manifestSourceAmends += " --amend ompzowe/server-bundle:s390x-sources"
}
// publish images
sh publishCommands +
"export DOCKER_CLI_EXPERIMENTAL=enabled\n" +
"docker manifest create ompzowe/server-bundle:latest ${manifestAmends}\n" +
"docker manifest push ompzowe/server-bundle:latest\n" +
"docker manifest create ompzowe/server-bundle:v${params.ZOWE_RELEASE_VERSION} ${manifestAmends}\n" +
"docker manifest push ompzowe/server-bundle:v${params.ZOWE_RELEASE_VERSION}"
// publish source images
if (manifestSourceAmends) {
sh publishCommands +
"export DOCKER_CLI_EXPERIMENTAL=enabled\n" +
"docker manifest create ompzowe/server-bundle:latest-sources ${manifestSourceAmends}\n" +
"docker manifest push ompzowe/server-bundle:latest-sources\n" +
"docker manifest create ompzowe/server-bundle:v${params.ZOWE_RELEASE_VERSION}-sources ${manifestSourceAmends}\n" +
"docker manifest push ompzowe/server-bundle:v${params.ZOWE_RELEASE_VERSION}-sources"
}
}
}
)
pipeline.createStage(
name : "Message",
isSkippable : true,
stage : {
// update build description with release version
currentBuild.description = "v${params.ZOWE_RELEASE_VERSION}".toString()
def source = "Build #${params.ZOWE_BUILD_NUMBER}"
def smpeMessage = ''
if (releaseArtifacts['smpe-zip'] && releaseArtifacts['smpe-zip']['target']) {
smpeMessage = """
SMP/e build:
${lib.Constants.DEFAULT_LFJ_ARTIFACTORY_URL}/${releaseFilePath}/${releaseArtifacts['smpe-zip']['target']}
"""
}
def dockeramd64Message = ''
if (releaseArtifacts['docker-amd64'] && releaseArtifacts['docker-amd64']['target']) {
dockeramd64Message = """
docker amd64 image:
${lib.Constants.DEFAULT_LFJ_ARTIFACTORY_URL}/${releaseFilePath}/${releaseArtifacts['docker-amd64']['target']}
"""
}
def dockers390xMessage = ''
if (releaseArtifacts['docker-s390x'] && releaseArtifacts['docker-s390x']['target']) {
dockers390xMessage = """
docker s390x image:
${lib.Constants.DEFAULT_LFJ_ARTIFACTORY_URL}/${releaseFilePath}/${releaseArtifacts['docker-s390x']['target']}
"""
}
def containerizationMessage = ''
if (releaseArtifacts['containerization'] && releaseArtifacts['containerization']['target']) {
containerizationMessage = """
containerization:
${lib.Constants.DEFAULT_LFJ_ARTIFACTORY_URL}/${releaseFilePath}/${releaseArtifacts['containerization']['target']}
"""
}
def successMsg = """
*************************************************************************************************
${source} is promoted as Zowe v${params.ZOWE_RELEASE_VERSION}, you can download from:
${lib.Constants.DEFAULT_LFJ_ARTIFACTORY_URL}/${releaseFilePath}/${releaseArtifacts['zowe']['target']}
${smpeMessage}
${dockeramd64Message}
${dockers390xMessage}
${containerizationMessage}
The CLI Core Package is published here:
${lib.Constants.DEFAULT_LFJ_ARTIFACTORY_URL}/${releaseFilePath}/${releaseArtifacts['cli']['target']}
The CLI Plugins Package is published here:
${lib.Constants.DEFAULT_LFJ_ARTIFACTORY_URL}/${releaseFilePath}/${releaseArtifacts['cli-plugins']['target']}
*************************************************************************************************
"""
echo successMsg
},
timeout: [time: 2, unit: 'MINUTES']
)
pipeline.end()
}