Browse code

Jenkinsfile: don't mark build failed when failing to create bundles

Failing to archive the bundles should not mark the build as failed.
This can happen if a build is terminated early, or if (to be implemented)
an optional build-stage is skipped / failed;

```
2019-08-24T10:53:09.354Z] + bundleName=janky
[2019-08-24T10:53:09.354Z] + echo Creating janky-bundles.tar.gz
[2019-08-24T10:53:09.354Z] Creating janky-bundles.tar.gz
[2019-08-24T10:53:09.354Z] + xargs tar -czf janky-bundles.tar.gz
[2019-08-24T10:53:09.354Z] + find bundles -path */root/*overlay2 -prune -o -type f ( -name *-report.json -o -name *.log -o -name *.prof -o -name *-report.xml ) -print
[2019-08-24T10:53:09.354Z] find: bundles: No such file or directory
[2019-08-24T10:53:09.354Z] tar: Cowardly refusing to create an empty archive
[2019-08-24T10:53:09.354Z] Try 'tar --help' or 'tar --usage' for more information.
Error when executing always post condition:
hudson.AbortException: script returned exit code 123
at org.jenkinsci.plugins.workflow.steps.durable_task.DurableTaskStep$Execution.handleExit(DurableTaskStep.java:569)
at org.jenkinsci.plugins.workflow.steps.durable_task.DurableTaskStep$Execution.check(DurableTaskStep.java:515)
at org.jenkinsci.plugins.workflow.steps.durable_task.DurableTaskStep$Execution.run(DurableTaskStep.java:461)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
```

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
(cherry picked from commit a76ff632a4a833851ef36726c9e9bfb5e7dbed39)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2019/08/24 21:14:56
Showing 1 changed files
... ...
@@ -109,12 +109,15 @@ pipeline {
109 109
                                     docker run --rm -v "$WORKSPACE:/workspace" busybox chown -R "$(id -u):$(id -g)" /workspace
110 110
                                     '''
111 111
 
112
-                                    sh '''
113
-                                    echo 'Creating docker-py-bundles.tar.gz'
114
-                                    tar -czf docker-py-bundles.tar.gz bundles/test-docker-py/*.xml bundles/test-docker-py/*.log
115
-                                    '''
116
-
117
-                                    archiveArtifacts artifacts: '*-bundles.tar.gz', allowEmptyArchive: true
112
+                                    catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE', message: 'Failed to create bundles.tar.gz') {
113
+                                        sh '''
114
+                                        bundleName=docker-py
115
+                                        echo "Creating ${bundleName}-bundles.tar.gz"
116
+                                        tar -czf ${bundleName}-bundles.tar.gz bundles/test-docker-py/*.xml bundles/test-docker-py/*.log
117
+                                        '''
118
+
119
+                                        archiveArtifacts artifacts: '*-bundles.tar.gz', allowEmptyArchive: true
120
+                                    }
118 121
                                 }
119 122
                             }
120 123
                         }
... ...
@@ -200,12 +203,15 @@ pipeline {
200 200
                             docker run --rm -v "$WORKSPACE:/workspace" busybox chown -R "$(id -u):$(id -g)" /workspace
201 201
                             '''
202 202
 
203
-                            sh '''
204
-                            echo 'Creating unit-bundles.tar.gz'
205
-                            tar -czvf unit-bundles.tar.gz bundles/junit-report.xml bundles/go-test-report.json bundles/profile.out
206
-                            '''
203
+                            catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE', message: 'Failed to create bundles.tar.gz') {
204
+                                sh '''
205
+                                bundleName=unit
206
+                                echo "Creating ${bundleName}-bundles.tar.gz"
207
+                                tar -czvf ${bundleName}-bundles.tar.gz bundles/junit-report.xml bundles/go-test-report.json bundles/profile.out
208
+                                '''
207 209
 
208
-                            archiveArtifacts artifacts: '*-bundles.tar.gz', allowEmptyArchive: true
210
+                                archiveArtifacts artifacts: '*-bundles.tar.gz', allowEmptyArchive: true
211
+                            }
209 212
                         }
210 213
                         cleanup {
211 214
                             sh 'make clean'
... ...
@@ -317,13 +323,16 @@ pipeline {
317 317
                             docker run --rm -v "$WORKSPACE:/workspace" busybox chown -R "$(id -u):$(id -g)" /workspace
318 318
                             '''
319 319
 
320
-                            sh '''
321
-                            echo "Creating janky-bundles.tar.gz"
322
-                            # exclude overlay2 directories
323
-                            find bundles -path '*/root/*overlay2' -prune -o -type f \\( -name '*.log' -o -name '*.prof' \\) -print | xargs tar -czf janky-bundles.tar.gz
324
-                            '''
320
+                            catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE', message: 'Failed to create bundles.tar.gz') {
321
+                                sh '''
322
+                                bundleName=janky
323
+                                echo "Creating ${bundleName}-bundles.tar.gz"
324
+                                # exclude overlay2 directories
325
+                                find bundles -path '*/root/*overlay2' -prune -o -type f \\( -o -name '*.log' -o -name '*.prof' \\) -print | xargs tar -czf ${bundleName}-bundles.tar.gz
326
+                                '''
325 327
 
326
-                            archiveArtifacts artifacts: '*-bundles.tar.gz', allowEmptyArchive: true
328
+                                archiveArtifacts artifacts: '*-bundles.tar.gz', allowEmptyArchive: true
329
+                            }
327 330
                         }
328 331
                         cleanup {
329 332
                             sh 'make clean'
... ...
@@ -411,13 +420,16 @@ pipeline {
411 411
                             docker run --rm -v "$WORKSPACE:/workspace" busybox chown -R "$(id -u):$(id -g)" /workspace
412 412
                             '''
413 413
 
414
-                            sh '''
415
-                            echo "Creating s390x-integration-bundles.tar.gz"
416
-                            # exclude overlay2 directories
417
-                            find bundles -path '*/root/*overlay2' -prune -o -type f \\( -name '*.log' -o -name '*.prof' \\) -print | xargs tar -czf s390x-integration-bundles.tar.gz
418
-                            '''
414
+                            catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE', message: 'Failed to create bundles.tar.gz') {
415
+                                sh '''
416
+                                bundleName=s390x-integration
417
+                                echo "Creating ${bundleName}-bundles.tar.gz"
418
+                                # exclude overlay2 directories
419
+                                find bundles -path '*/root/*overlay2' -prune -o -type f \\( -o -name '*.log' -o -name '*.prof' \\) -print | xargs tar -czf ${bundleName}-bundles.tar.gz
420
+                                '''
419 421
 
420
-                            archiveArtifacts artifacts: '*-bundles.tar.gz', allowEmptyArchive: true
422
+                                archiveArtifacts artifacts: '*-bundles.tar.gz', allowEmptyArchive: true
423
+                            }
421 424
                         }
422 425
                         cleanup {
423 426
                             sh 'make clean'
... ...
@@ -486,12 +498,16 @@ pipeline {
486 486
                             docker run --rm -v "$WORKSPACE:/workspace" busybox chown -R "$(id -u):$(id -g)" /workspace
487 487
                             '''
488 488
 
489
-                            sh '''
490
-                            echo "Creating s390x-integration-cli-bundles.tar.gz"
491
-                            find bundles -path '*/root/*overlay2' -prune -o -type f \\( -name '*.log' -o -name '*.prof' \\) -print | xargs tar -czf s390x-integration-cli-bundles.tar.gz
492
-                            '''
489
+                            catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE', message: 'Failed to create bundles.tar.gz') {
490
+                                sh '''
491
+                                bundleName=s390x-integration-cli
492
+                                echo "Creating ${bundleName}-bundles.tar.gz"
493
+                                # exclude overlay2 directories
494
+                                find bundles -path '*/root/*overlay2' -prune -o -type f \\( -o -name '*.log' -o -name '*.prof' \\) -print | xargs tar -czf ${bundleName}-bundles.tar.gz
495
+                                '''
493 496
 
494
-                            archiveArtifacts artifacts: '*-bundles.tar.gz', allowEmptyArchive: true
497
+                                archiveArtifacts artifacts: '*-bundles.tar.gz', allowEmptyArchive: true
498
+                            }
495 499
                         }
496 500
                         cleanup {
497 501
                             sh 'make clean'
... ...
@@ -577,13 +593,16 @@ pipeline {
577 577
                             docker run --rm -v "$WORKSPACE:/workspace" busybox chown -R "$(id -u):$(id -g)" /workspace
578 578
                             '''
579 579
 
580
-                            sh '''
581
-                            echo "Creating powerpc-integration-bundles.tar.gz"
582
-                            # exclude overlay2 directories
583
-                            find bundles -path '*/root/*overlay2' -prune -o -type f \\( -name '*.log' -o -name '*.prof' \\) -print | xargs tar -czf powerpc-integration-bundles.tar.gz
584
-                            '''
580
+                            catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE', message: 'Failed to create bundles.tar.gz') {
581
+                                sh '''
582
+                                bundleName=powerpc-integration
583
+                                echo "Creating ${bundleName}-bundles.tar.gz"
584
+                                # exclude overlay2 directories
585
+                                find bundles -path '*/root/*overlay2' -prune -o -type f \\( -o -name '*.log' -o -name '*.prof' \\) -print | xargs tar -czf ${bundleName}-bundles.tar.gz
586
+                                '''
585 587
 
586
-                            archiveArtifacts artifacts: '*-bundles.tar.gz', allowEmptyArchive: true
588
+                                archiveArtifacts artifacts: '*-bundles.tar.gz', allowEmptyArchive: true
589
+                            }
587 590
                         }
588 591
                         cleanup {
589 592
                             sh 'make clean'
... ...
@@ -650,12 +669,16 @@ pipeline {
650 650
                             docker run --rm -v "$WORKSPACE:/workspace" busybox chown -R "$(id -u):$(id -g)" /workspace
651 651
                             '''
652 652
 
653
-                            sh '''
654
-                            echo "Creating powerpc-integration-cli-bundles.tar.gz"
655
-                            find bundles -path '*/root/*overlay2' -prune -o -type f \\( -name '*.log' -o -name '*.prof' \\) -print | xargs tar -czf powerpc-integration-cli-bundles.tar.gz
656
-                            '''
653
+                            catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE', message: 'Failed to create bundles.tar.gz') {
654
+                                sh '''
655
+                                bundleName=powerpc-integration-cli
656
+                                echo "Creating ${bundleName}-bundles.tar.gz"
657
+                                # exclude overlay2 directories
658
+                                find bundles -path '*/root/*overlay2' -prune -o -type f \\( -o -name '*.log' -o -name '*.prof' \\) -print | xargs tar -czf ${bundleName}-bundles.tar.gz
659
+                                '''
657 660
 
658
-                            archiveArtifacts artifacts: '*-bundles.tar.gz', allowEmptyArchive: true
661
+                                archiveArtifacts artifacts: '*-bundles.tar.gz', allowEmptyArchive: true
662
+                            }
659 663
                         }
660 664
                         cleanup {
661 665
                             sh 'make clean'