@@ -363,14 +363,32 @@ def build(command, cell) {
363363 def script_vars = " #!/bin/bash \n set -o pipefail ; " // pipe to tee needs pipefail
364364 script_vars = " ${ script_vars} m2_dir=\' ${ WORKSPACE} /build/m2\' "
365365 timeout(time : 1 , unit : ' HOURS' ) {
366- def status = sh label : " RUNNING ${ cell.step} ..." , script : " ${ script_vars} ${ build_script} ${ cell.jdk} 2>&1 | tee >( xz -c > build/${ logfile} )" , returnStatus : true
367- dir(" build" ) {
368- archiveArtifacts artifacts : " ${ logfile} " , fingerprint : true
369- copyToNightlies(" ${ logfile} " , " ${ cell.step} /jdk${ cell.jdk} /${ cell.arch} /" )
370- }
371- if (0 != status) { error(" Stage ${ cell.step}${ cell_suffix} failed with exit status ${ status} " ) }
372- if (" jar" == cell. step) {
373- stash name : " ${ cell.arch} _${ cell.jdk} "
366+ try {
367+ def status = sh label : " RUNNING ${ cell.step} ..." , script : " ${ script_vars} ${ build_script} ${ cell.jdk} 2>&1 | tee >( xz -c > build/${ logfile} )" , returnStatus : true
368+ dir(" build" ) {
369+ archiveArtifacts artifacts : " ${ logfile} " , fingerprint : true
370+ copyToNightlies(" ${ logfile} " , " ${ cell.step} /jdk${ cell.jdk} /${ cell.arch} /" )
371+ }
372+ if (0 != status) { error(" Stage ${ cell.step}${ cell_suffix} failed with exit status ${ status} " ) }
373+ if (" jar" == cell. step) {
374+ stash name : " ${ cell.arch} _${ cell.jdk} "
375+ }
376+ } catch (exc) {
377+ if (exc. getClass(). getName() == " org.jenkinsci.plugins.workflow.steps.FlowInterruptedException" ) {
378+ def causes = exc. getCauses()
379+ causes. each { cause ->
380+ echo " CauseOfInterruption: ${ cause.getClass().getName()} - ${ cause.getShortDescription()} "
381+ }
382+ def isUserAbort = causes. any {
383+ it. getClass(). getName(). contains(" CauseOfInterruption\$ UserInterruption" )
384+ }
385+ if (isUserAbort) {
386+ throw exc // user explicitly aborted — do not retry
387+ }
388+ // agent loss or timeout: wrap so retry() can catch and loop again
389+ throw new Exception (" Retryable interruption: ${ causes.collect { it.getShortDescription() }.join(', ')} " , exc)
390+ }
391+ throw exc
374392 }
375393 }
376394 dir(" build" ) {
@@ -417,10 +435,19 @@ def test(command, cell) {
417435 }
418436 if (0 != status) { error(" Stage ${ cell.step}${ cell_suffix} failed with exit status ${ status} " ) }
419437 } catch (exc) {
420- if (exc. getClass(). getName() == " org.jenkinsci.plugins.workflow.steps.FlowInterruptedException" ) {
421- for (def causeOfInterruption in exc. getCauses()) {
422- echo " CauseOfInterruption: ${ causeOfInterruption.getClass().getName()} - ${ causeOfInterruption.getShortDescription()} "
438+ if (" org.jenkinsci.plugins.workflow.steps.FlowInterruptedException" == exc. getClass(). getName()) {
439+ def causes = exc. getCauses()
440+ causes. each { cause ->
441+ echo " CauseOfInterruption: ${ cause.getClass().getName()} - ${ cause.getShortDescription()} "
442+ }
443+ def isUserAbort = causes. any {
444+ it. getClass(). getName(). contains(" CauseOfInterruption$UserInterruption " )
445+ }
446+ if (isUserAbort) {
447+ throw exc // user explicitly aborted — do not retry
423448 }
449+ // agent loss or timeout: wrap so retry() can catch and loop again
450+ throw new Exception (" Retryable interruption: ${ causes.collect { it.getShortDescription() }.join(', ')} " , exc)
424451 }
425452 throw exc
426453 } finally {
0 commit comments