-
Notifications
You must be signed in to change notification settings - Fork 74
/
Jenkinsfile
1491 lines (1329 loc) · 65.6 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
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
pipeline {
agent {
label 'vagrant_kvm_builder'
}
environment {
TD_GITHUB = credentials('cbaa2c3c-151e-4ba2-92ed-8f088762467b')
GITHUB = credentials('88f234ac-6b93-4c41-92d2-1329c97e2254')
ARTIFACTORY = credentials('d1a4e414-0526-4973-bea5-9d219d884f03')
GITHUB_TOKEN = credentials('72702790-6cee-470b-94d0-1c3eb246a71d')
BLACKDUCK_TOKEN = credentials('cb9c5430-f974-46e3-9d25-baeab4873db9')
ESXI_PASS = credentials('8af95130-9b78-4e7a-9d3a-bec7ab54716b')
JENKINS = credentials('8b24c6e2-8589-4feb-afc2-3d0175854b11')
PIPELINE = env.JOB_NAME.split('/')[0].trim()
PLATFORM = env.PIPELINE.split('-')[-1].trim()
NORMALIZED_BRANCH = env.BRANCH_NAME.replaceAll('[/-]', '_')
ART_URL = "https://sdartifact.td.teradata.com/artifactory"
ART_ISO_PATH = "software-manufacturing/pallets/stacki"
ART_QCOW_PATH = "software-manufacturing/kvm-images/stacki"
ART_OVA_PATH = "software-manufacturing/ova-images/stacki"
ART_VBOX_PATH = "software-manufacturing/vbox-images/stacki"
}
options {
ansiColor('xterm')
buildDiscarder(logRotator(daysToKeepStr: env.BRANCH_NAME == 'master' ? '365' : '20'))
skipDefaultCheckout()
timestamps()
}
triggers {
// Nightly build of develop (at 3am)
cron(env.BRANCH_NAME == 'develop' ? 'TZ=America/Los_Angeles\n0 3 * * *' : '')
}
stages {
stage('Source') {
steps {
// Update the Stacki Builds website
build job: 'rebuild_stacki-builds_website', wait: false
// Get the souce code we're going to build
// Note: github.com checkout is flaky, so we disable the default checkout
// and do it here with retries.
dir('stacki') {
retry(3) {
script {
// Note: There is a bug in Jenkins where a timeout causes the job to
// abort unless you catch the FlowInterruptedException.
// https://issues.jenkins-ci.org/browse/JENKINS-51454
timeout(15) {
try {
// Note: there is currently a bug in scm checkout where it doesn't
// set environment variables, we we do by hand in a script
checkout(scm).each { k,v -> env.setProperty(k, v) }
// Remove the git reference because it breaks stack-releasenotes
sh('git repack -a -d')
sh('rm -f .git/objects/info/alternates')
// Add the last git log subject as the description in the GUI
currentBuild.description = sh(
returnStdout: true,
script: 'git log -1 --pretty=format:%s'
)
}
catch (org.jenkinsci.plugins.workflow.steps.FlowInterruptedException e) {
error 'Source checkout timed out'
}
}
}
}
}
// Get the repository testing scripts
sh 'git clone https://${TD_GITHUB}@github.td.teradata.com/software-manufacturing/stacki-git-tests.git'
}
}
stage('Check Branch') {
// Only need these checks on one platform for feature and bugfix branches
when {
environment name: 'PLATFORM', value: 'sles15'
anyOf {
branch 'feature/*'
branch 'bugfix/*'
}
}
parallel {
stage('Number Of Commits') {
steps {
dir('stacki') {
script {
// Check the number of commits on the branch
def status = sh(
returnStatus: true,
script: "python3 ../stacki-git-tests/verify-branch-base.py"
)
// Report the status to github.com
if (status == 0) {
githubNotify(
context: 'Check: Branch commits',
status: 'SUCCESS',
description: 'ready to merge'
)
}
else {
githubNotify(
context: 'Check: Branch commits',
status: 'FAILURE',
description: 'not ready to merge'
)
}
}
}
}
}
stage('Commit Message') {
steps {
dir('stacki') {
script {
// Check the commit message formatting
def status = sh(
returnStatus: true,
script: 'python3 ../stacki-git-tests/validate-commit-message.py'
)
// Report the status to github.com
if (status == 0) {
githubNotify(
context: 'Check: Commit message',
status: 'SUCCESS',
description: 'ready to merge'
)
}
else {
githubNotify(
context: 'Check: Commit message',
status: 'FAILURE',
description: 'not ready to merge'
)
}
}
}
}
}
}
}
stage('Build') {
environment {
ISOS = '../../..'
PYPI_CACHE = 'true'
}
steps {
// Figure out if we are a release build
script {
if (env.TAG_NAME ==~ /stacki-.*/ && env.BRANCH_NAME == env.TAG_NAME) {
env.IS_RELEASE = 'true'
}
else {
env.IS_RELEASE = 'false'
}
}
// Get some ISOs we'll need for build
script {
switch(env.PLATFORM) {
case 'redhat7':
sh 'cp /export/www/installer-isos/CentOS-7-x86_64-Everything-1810.iso .'
// sh 'cp /export/www/stacki-isos/redhat7/os/os-7.6_20191101-redhat7.x86_64.disk1.iso .'
// env.OS_PALLET = 'os-7.6_20191101-redhat7.x86_64.disk1.iso'
break
case 'sles15':
sh 'cp /export/www/installer-isos/SLE-15-SP1-Installer-DVD-x86_64-GM-DVD1.iso .'
sh 'cp /export/www/installer-isos/SLE-15-SP1-Packages-x86_64-GM-DVD1.iso .'
break
case 'sles12':
sh 'cp /export/www/installer-isos/SLE-12-SP3-Server-DVD-x86_64-GM-DVD1.iso .'
sh 'cp /export/www/installer-isos/SLE-12-SP3-SDK-DVD-x86_64-GM-DVD1.iso .'
break
case 'sles11':
sh 'cp /export/www/installer-isos/SLES-11-SP3-DVD-x86_64-GM-DVD1.iso .'
sh 'cp /export/www/installer-isos/SLE-11-SP3-SDK-DVD-x86_64-GM-DVD1.iso .'
break
}
}
// Build our ISO
dir('stacki/tools/iso-builder') {
// Give the build up to 60 minutes to finish
timeout(60) {
script {
try {
sh 'vagrant up'
}
catch (org.jenkinsci.plugins.workflow.steps.FlowInterruptedException e) {
error 'Build timed out'
}
}
}
}
// Move the ISO into the root of the workspace, renaming it for TSS if needed
script {
sh 'mv stacki/stacki-*.iso ./'
switch(env.PLATFORM) {
case 'sles15':
sh 'mv $(ls ./stacki-*.iso) $(ls ./stacki-*.iso | sed -e "s|stacki-|stacki-15.1-|")'
break
case 'sles12':
sh 'mv $(ls ./stacki-*.iso) $(ls ./stacki-*.iso | sed -e "s|stacki-|stacki-12.3-|")'
break
case 'sles11':
sh 'mv $(ls ./stacki-*.iso) $(ls ./stacki-*.iso | sed -e "s|stacki-|stacki-11.3-|")'
break
case 'redhat7':
// Note: For now, we no longer build StackiOS
// sh 'mv stacki/stackios-*.iso ./'
break
}
}
// Set an environment variable with the ISO filename
script {
env.ISO_FILENAME = findFiles(glob: 'stacki-*.iso')[0].name
}
// Fingerprint the file, which Jenkins or our pipeline might use some day
fingerprint "${env.ISO_FILENAME}"
// If we are Redhat, fingerprint the StackiOS ISO as well
// script {
// if (env.PLATFORM == 'redhat7') {
// env.STACKIOS_FILENAME = findFiles(glob: 'stackios-*.iso')[0].name
// fingerprint "${env.STACKIOS_FILENAME}"
// }
// }
}
post {
always {
// Update the Stacki Builds website
build job: 'rebuild_stacki-builds_website', wait: false
// Remove the pallet builder VM
dir('stacki/tools/iso-builder') {
sh 'vagrant destroy -f || true'
}
}
success {
// Tell github.com this commit built
githubNotify(
context: "Build: ${env.PLATFORM}",
description: "build succeeded",
status: 'SUCCESS'
)
}
failure {
// Tell github.com this commit failed to build
githubNotify(
context: "Build: ${env.PLATFORM}",
description: "build failed",
status: 'FAILURE'
)
// And the Slack #stacki-bot channel
slackSend(
channel: '#stacki-builds',
color: 'danger',
message: """\
Stacki build has failed.
*Branch:* ${env.GIT_BRANCH}
*OS:* ${env.PLATFORM}
<${env.RUN_DISPLAY_URL}|View the pipeline job>
""".stripIndent(),
tokenCredentialId: 'slack-token-stacki'
)
}
}
}
stage('Upload') {
parallel {
stage('Artifactory') {
steps {
// Setup Artifactory access
rtServer(
id: "td-artifactory",
url: "${env.ART_URL}",
credentialsId: "d1a4e414-0526-4973-bea5-9d219d884f03",
timeout: 3600
)
// Figure out our Artifactory OS
script {
env.ART_OS = [
'sles11': 'sles-11.3',
'sles12': 'sles-12.3',
'sles15': 'sles-15.1',
'redhat7': 'redhat-7.4'
][env.PLATFORM]
}
// Upload the Stacki ISO to artifactory snapshot
rtUpload(
serverId: "td-artifactory",
spec: """
{
"files": [{
"pattern": "${env.ISO_FILENAME}",
"target": "pkgs-external-snapshot-sd/${env.ART_ISO_PATH}/${env.ART_OS}/${env.GIT_BRANCH}/"
}]
}
"""
)
}
post {
failure {
// Notify the Slack #stacki-bot channel
slackSend(
channel: '#stacki-builds',
color: 'danger',
message: """\
Stacki failed to upload to Artifactory.
*Branch:* ${env.GIT_BRANCH}
*OS:* ${env.PLATFORM}
<${env.RUN_DISPLAY_URL}|View the pipeline job>
""".stripIndent(),
tokenCredentialId: 'slack-token-stacki'
)
}
}
}
stage('Stacki Builds') {
steps {
// Create our MD5 of the ISO
sh 'md5sum $ISO_FILENAME > $ISO_FILENAME.md5'
// Make sure our web directory exists
sh 'mkdir -p /export/www/stacki-isos/$PLATFORM/stacki/$NORMALIZED_BRANCH'
// Copy the files over
sh 'cp $ISO_FILENAME /export/www/stacki-isos/$PLATFORM/stacki/$NORMALIZED_BRANCH/'
sh 'cp $ISO_FILENAME.md5 /export/www/stacki-isos/$PLATFORM/stacki/$NORMALIZED_BRANCH/'
// Note: For now, we no longer build StackiOS
// If we are Redhat, we should have a StackiOS ISO as well
// script {
// if (env.PLATFORM == 'redhat7') {
// // Create our MD5 of the ISO
// sh 'md5sum $STACKIOS_FILENAME > $STACKIOS_FILENAME.md5'
// // Make sure our web directory exists
// sh 'mkdir -p /export/www/stacki-isos/redhat7/stackios/$NORMALIZED_BRANCH'
// // Copy the files over
// sh 'cp $STACKIOS_FILENAME /export/www/stacki-isos/redhat7/stackios/$NORMALIZED_BRANCH/'
// sh 'cp $STACKIOS_FILENAME.md5 /export/www/stacki-isos/redhat7/stackios/$NORMALIZED_BRANCH/'
// }
// }
}
post {
failure {
// Notify the Slack #stacki-builds channel
slackSend(
channel: '#stacki-builds',
color: 'danger',
message: """\
Stacki failed to copy to Stacki Builds website.
*Branch:* ${env.GIT_BRANCH}
*OS:* ${env.PLATFORM}
<${env.RUN_DISPLAY_URL}|View the pipeline job>
""".stripIndent(),
tokenCredentialId: 'slack-token-stacki'
)
}
}
}
}
}
stage('Setup Tests') {
steps {
// Build the test-framework
dir('stacki/test-framework') {
sh 'make'
}
// Pre-cache the installer ISOs
dir('stacki/test-framework/.cache') {
script {
switch(env.PLATFORM) {
case 'redhat7':
sh 'cp /export/www/installer-isos/CentOS-7-x86_64-Everything-1810.iso .'
break
case 'sles15':
sh 'cp /export/www/installer-isos/SLE-15-SP1-Installer-DVD-x86_64-GM-DVD1.iso .'
sh 'cp /export/www/installer-isos/SLE-15-SP1-Packages-x86_64-GM-DVD1.iso .'
break
case 'sles12':
sh 'cp /export/www/installer-isos/SLE-12-SP3-Server-DVD-x86_64-GM-DVD1.iso .'
sh 'cp /export/www/installer-isos/SLE-12-SP3-SDK-DVD-x86_64-GM-DVD1.iso .'
break
case 'sles11':
sh 'cp /export/www/installer-isos/SLE-12-SP3-Server-DVD-x86_64-GM-DVD1.iso .'
sh 'cp /export/www/installer-isos/SLE-12-SP3-SDK-DVD-x86_64-GM-DVD1.iso .'
sh 'cp /export/www/installer-isos/SLES-11-SP3-DVD-x86_64-GM-DVD1.iso .'
sh 'cp /export/www/installer-isos/SLE-11-SP3-SDK-DVD-x86_64-GM-DVD1.iso .'
break
}
}
}
// Make a copy of test-framework for each test suite
sh 'cp -al stacki/test-framework unit'
sh 'cp -al stacki/test-framework integration_1'
sh 'cp -al stacki/test-framework integration_2'
sh 'cp -al stacki/test-framework integration_3'
sh 'cp -al stacki/test-framework integration_4'
sh 'cp -al stacki/test-framework system'
script {
// releases, develop branch, and branches ending in _cov get coverage reports
if (env.PLATFORM != 'sles11' && (env.IS_RELEASE == 'true' || env.GIT_BRANCH ==~ /develop|.*_cov/ || currentBuild.description ==~ /(?si).*\bcoverage\b.*/)) {
env.COVERAGE_REPORTS = 'true'
// A VM to combine all the coverage into a combined report
sh 'cp -al stacki/test-framework combine'
// A folder for the coverage reports to land in
sh 'mkdir coverage'
}
else {
env.COVERAGE_REPORTS = 'false'
}
// If we're SLES 11, use a matching SLES 12 Stacki pallet to be our frontend
// Note: Give it 20 minutes to show up (will usually take 10)
if (env.PLATFORM == 'sles11') {
retry(20) {
sh '''
SLES12_ISO_FILENAME=$(echo $ISO_FILENAME | sed -e 's|stacki-11.3|stacki-12.3|' -e 's|sles11.x86_64|sles12.x86_64|')
curl -H "X-JFrog-Art-Api:${ARTIFACTORY_PSW}" -sfSLO --retry 3 "https://sdartifact.td.teradata.com/artifactory/pkgs-external-snapshot-sd/$ART_ISO_PATH/sles-12.3/$GIT_BRANCH/$SLES12_ISO_FILENAME" || (STATUS=$? && sleep 60 && exit $STATUS)
'''
}
}
}
}
post {
always {
// Update the Stacki Builds website
build job: 'rebuild_stacki-builds_website', wait: false
}
failure {
// Notify the Slack #stacki-builds channel
slackSend(
channel: '#stacki-builds',
color: 'danger',
message: """\
Stacki failed to setup tests.
*Branch:* ${env.GIT_BRANCH}
*OS:* ${env.PLATFORM}
<${env.RUN_DISPLAY_URL}|View the pipeline job>
""".stripIndent(),
tokenCredentialId: 'slack-token-stacki'
)
}
}
}
stage('Tests') {
parallel {
stage('Unit') {
when {
not {
environment name: 'PLATFORM', value: 'sles11'
}
}
steps {
// Run the unit tests
dir('unit') {
// Give the tests up to 60 minutes to finish
timeout(60) {
script {
try {
if (env.COVERAGE_REPORTS == 'true') {
sh './run-tests.sh --unit --coverage ../$ISO_FILENAME'
}
else {
sh './run-tests.sh --unit ../$ISO_FILENAME'
}
}
catch (org.jenkinsci.plugins.workflow.steps.FlowInterruptedException e) {
// Make sure we clean up the VM
dir('test-suites/unit') {
sh 'vagrant destroy -f || true'
}
// Raise an error
error 'Unit test-suite timed out'
}
}
}
}
}
post {
always {
script {
// Record the test statuses for Jenkins
if (fileExists('unit/reports/unit-junit.xml')) {
junit 'unit/reports/unit-junit.xml'
}
if (env.COVERAGE_REPORTS == 'true') {
// Move the coverage report to the common folder
sh 'mv unit/reports/unit coverage/'
// Add the coverage data to the `combine` folder
sh 'mv unit/reports/unit.coverage combine/reports/'
}
}
}
}
}
stage('Integration - Group 1') {
when {
not {
environment name: 'PLATFORM', value: 'sles11'
}
}
steps {
run_integration_test_steps('1', '4')
}
post {
always {
run_integration_test_post('1')
}
}
}
stage('Integration - Group 2') {
when {
not {
environment name: 'PLATFORM', value: 'sles11'
}
}
steps {
run_integration_test_steps('2', '4')
}
post {
always {
run_integration_test_post('2')
}
}
}
stage('Integration - Group 3') {
when {
not {
environment name: 'PLATFORM', value: 'sles11'
}
}
steps {
run_integration_test_steps('3', '4')
}
post {
always {
run_integration_test_post('3')
}
}
}
stage('Integration - Group 4') {
when {
not {
environment name: 'PLATFORM', value: 'sles11'
}
}
steps {
run_integration_test_steps('4', '4')
}
post {
always {
run_integration_test_post('4')
}
}
}
stage('System') {
steps {
// Run the system tests
dir('system') {
// Give the tests up to 90 minutes to finish
timeout(90) {
script {
try {
if (env.PLATFORM == 'sles11') {
sh './run-tests.sh --system --extra-isos=../$ISO_FILENAME ../stacki-*-sles12.x86_64.disk1.iso'
}
else {
if (env.COVERAGE_REPORTS == 'true') {
sh './run-tests.sh --system --coverage ../$ISO_FILENAME'
}
else {
sh './run-tests.sh --system ../$ISO_FILENAME'
}
}
}
catch (org.jenkinsci.plugins.workflow.steps.FlowInterruptedException e) {
// Take a screenshots of the machine screens
sh 'virsh screenshot $(cat .vagrant/machines/frontend/libvirt/id) screenshot-frontend.ppm'
sh 'convert screenshot-frontend.ppm screenshot-frontend.png'
archiveArtifacts 'screenshot-frontend.png'
sh 'virsh screenshot $(cat .vagrant/machines/backend-0-0/libvirt/id) screenshot-backend-0-0.ppm'
sh 'convert screenshot-backend-0-0.ppm screenshot-backend-0-0.png'
archiveArtifacts 'screenshot-backend-0-0.png'
sh 'virsh screenshot $(cat .vagrant/machines/backend-0-1/libvirt/id) screenshot-backend-0-1.ppm'
sh 'convert screenshot-backend-0-1.ppm screenshot-backend-0-1.png'
archiveArtifacts 'screenshot-backend-0-1.png'
// Make sure we clean up the VM
dir('test-suites/system') {
sh 'vagrant destroy -f || true'
}
// Raise an error
error 'System test-suite timed out'
}
}
}
}
}
post {
always {
script {
// Record the test statuses for Jenkins
if (fileExists('system/reports/system-junit.xml')) {
junit 'system/reports/system-junit.xml'
}
if (env.COVERAGE_REPORTS == 'true') {
// Move the coverage report to the common folder
sh 'mv system/reports/system coverage/'
// Add the coverage data to the `combine` folder
sh 'mv system/reports/system.coverage combine/reports/'
}
}
}
}
}
// Note: No more StackiOS until further notice
// stage('StackiOS') {
// when {
// environment name: 'PLATFORM', value: 'redhat7'
// anyOf {
// branch 'develop'
// environment name: 'IS_RELEASE', value: 'true'
// }
// }
//
// steps {
// build job: 'test_stackios', parameters: [
// string(name: 'STACKIOS_ISO', value: "http://stacki-builds.labs.teradata.com/stacki-isos/redhat7/stackios/${env.NORMALIZED_BRANCH}/${env.STACKIOS_FILENAME}"),
// string(name: 'STACKI_BRANCH', value: "${env.BRANCH_NAME}")
// ], wait: false
// }
// }
stage('Combine') {
when {
environment name: 'COVERAGE_REPORTS', value: 'true'
}
steps {
dir('combine/test-suites/unit') {
script {
// Create a VM to combine the coverage data
sh './set-up.sh ../../../$ISO_FILENAME'
}
}
}
}
}
post {
always {
script {
if (env.COVERAGE_REPORTS == 'true') {
// Combine the coverage data
dir('combine/test-suites/unit') {
sh '''
set +e
source ../../bin/activate
vagrant ssh frontend -c "sudo -i coverage combine /export/reports/integration-*.coverage"
vagrant ssh frontend -c "sudo -i coverage html -d /export/reports/integration/"
vagrant ssh frontend -c "sudo -i mv /root/.coverage /export/reports/integration.coverage"
vagrant ssh frontend -c "sudo -i coverage combine /export/reports/*.coverage"
vagrant ssh frontend -c "sudo -i coverage html -d /export/reports/all/"
./tear-down.sh
deactivate
'''
}
// Move our new `integration` and `all` coverage reports to the common folder
sh 'mv combine/reports/integration coverage/'
sh 'mv combine/reports/all coverage/'
// Publish the coverage reports
publishHTML(
allowMissing: true,
alwaysLinkToLastBuild: false,
keepAll: true,
reportDir: 'coverage',
reportFiles: 'all/index.html,unit/index.html,integration/index.html,system/index.html',
reportName: 'Code Coverage',
reportTitles: 'All,Unit,Integration,System'
)
}
// Update the Stacki Builds website
build job: 'rebuild_stacki-builds_website', wait: false
}
}
success {
// Tell github.com this commit passed tests
githubNotify(
context: "Test: ${env.PLATFORM}",
description: "tests succeeded",
status: 'SUCCESS'
)
script {
if (env.GIT_BRANCH != 'develop' && env.IS_RELEASE != 'true') {
// And the Slack #stacki-builds channel
slackSend(
channel: '#stacki-builds',
color: 'good',
message: """\
Stacki build and test has succeeded.
*Branch:* ${env.GIT_BRANCH}
*OS:* ${env.PLATFORM}
*ISO:* ${env.ISO_FILENAME}
*URL:* ${env.ART_URL}/pkgs-external-snapshot-sd/${env.ART_ISO_PATH}/${env.ART_OS}/${env.GIT_BRANCH}/${env.ISO_FILENAME}
""".stripIndent(),
tokenCredentialId: 'slack-token-stacki'
)
}
}
}
failure {
// Tell github.com this commit failed tests
githubNotify(
context: "Test: ${env.PLATFORM}",
description: "tests failed",
status: 'FAILURE'
)
// And the Slack #stacki-builds channel
slackSend(
channel: '#stacki-builds',
color: 'danger',
message: """\
Stacki tests have failed.
*Branch:* ${env.GIT_BRANCH}
*OS:* ${env.PLATFORM}
<https://sdvl3jenk015.td.teradata.com/blue/organizations/jenkins/stacki - ${env.PLATFORM}/detail/${env.JOB_BASE_NAME}/${env.BUILD_ID}/tests/|View the test results>
""".stripIndent(),
tokenCredentialId: 'slack-token-stacki'
)
}
}
}
stage('Promote') {
when {
anyOf {
branch 'develop'
environment name: 'IS_RELEASE', value: 'true'
}
}
parallel {
stage('Artifactory') {
steps {
// Figure out our Artifactory repo
script {
if (env.GIT_BRANCH == 'develop') {
env.ART_REPO = 'pkgs-external-qa-sd'
}
else {
env.ART_REPO = 'pkgs-external-released-sd'
}
}
// Upload the Stacki ISO to artifactory
rtUpload(
serverId: "td-artifactory",
spec: """
{
"files": [{
"pattern": "${env.ISO_FILENAME}",
"target": "${env.ART_REPO}/${env.ART_ISO_PATH}/${env.ART_OS}/"
}]
}
"""
)
}
post {
success {
// Tell #stacki-builds we succeeded
slackSend(
channel: '#stacki-builds',
color: 'good',
message: """\
Stacki build and test has succeeded.
*Branch:* ${env.GIT_BRANCH}
*OS:* ${env.PLATFORM}
*ISO:* ${env.ISO_FILENAME}
*URL:* ${env.ART_URL}/${env.ART_REPO}/${env.ART_ISO_PATH}/${env.ART_OS}/${env.ISO_FILENAME}
""".stripIndent(),
tokenCredentialId: 'slack-token-stacki'
)
// Notify Slack of a new release
script {
if (env.IS_RELEASE == 'true') {
slackSend(
channel: '#stacki-announce',
color: 'good',
message: """\
New Stacki ISO uploaded to Artifactory.
*ISO:* ${env.ISO_FILENAME}
*URL:* ${env.ART_URL}/${env.ART_REPO}/${env.ART_ISO_PATH}/${env.ART_OS}/${env.ISO_FILENAME}
""".stripIndent(),
tokenCredentialId: 'slack-token-stacki'
)
}
}
// Update the Stacki Builds website
build job: 'rebuild_stacki-builds_website', wait: false
}
failure {
// Notify the Slack #stacki-bot channel
slackSend(
channel: '#stacki-builds',
color: 'danger',
message: """\
Stacki failed to upload to Artifactory.
*Branch:* ${env.GIT_BRANCH}
*OS:* ${env.PLATFORM}
<${env.RUN_DISPLAY_URL}|View the pipeline job>
""".stripIndent(),
tokenCredentialId: 'slack-token-stacki'
)
}
}
}
stage('Amazon S3') {
when {
environment name: 'PLATFORM', value: 'redhat7'
environment name: 'IS_RELEASE', value: 'true'
}
steps {
withAWS(credentials:'amazon-s3-credentials') {
// Upload the Stacki ISO
s3Upload(
file: env.ISO_FILENAME,
bucket: 'teradata-stacki',
path: 'release/stacki/5.x/',
acl: 'PublicRead'
)
// Note: For now, we no longer build StackiOS
// And the StackiOS ISO
// s3Upload(
// file: env.STACKIOS_FILENAME,
// bucket: 'teradata-stacki',
// path: 'release/stacki/5.x/',
// acl: 'PublicRead'
// )
}
}
post {
success {
slackSend(
channel: '#stacki-builds',
color: 'good',
message: """\
New Stacki ISO uploaded to Amazon S3.
*Stacki:* http://teradata-stacki.s3.amazonaws.com/release/stacki/5.x/${env.ISO_FILENAME}
""".stripIndent(),
tokenCredentialId: 'slack-token-stacki'
)
}
failure {
slackSend(
channel: '#stacki-builds',
color: 'danger',
message: """\
Stacki ISO failed to upload to Amazon s3.
*Branch:* ${env.GIT_BRANCH}
*OS:* ${env.PLATFORM}
<${env.RUN_DISPLAY_URL}|View the pipeline job>
""".stripIndent(),
tokenCredentialId: 'slack-token-stacki'
)
}
}
}
}
}
stage('Post Build') {
when {
anyOf {
branch 'develop'
environment name: 'IS_RELEASE', value: 'true'
}
}
parallel {
stage('BlackDuck Scan') {
steps {
// Get a copy of blackduck-scanner
sh 'git clone https://${TD_GITHUB}@github.td.teradata.com/software-manufacturing/stacki-blackduck-scanner.git'
// Now do the scan
dir ('stacki-blackduck-scanner') {
script {
if (env.IS_RELEASE == 'true') {
sh './do-scan.sh release $PLATFORM $BLACKDUCK_TOKEN ../$ISO_FILENAME'
}
else {
sh './do-scan.sh nightly $PLATFORM $BLACKDUCK_TOKEN ../$ISO_FILENAME'
}
}
}
}
post {
failure {
// Notify the Slack #stacki-bot channel
slackSend(
channel: '#stacki-builds',
color: 'danger',
message: """\
Stacki Blackduck scan has failed.
*Branch:* ${env.GIT_BRANCH}
*OS:* ${env.PLATFORM}
<${env.RUN_DISPLAY_URL}|View the pipeline job>