diff --git a/buildenv/jenkins/JenkinsfileBase b/buildenv/jenkins/JenkinsfileBase index 24c8b3ec68..f1564ad02f 100644 --- a/buildenv/jenkins/JenkinsfileBase +++ b/buildenv/jenkins/JenkinsfileBase @@ -763,28 +763,54 @@ def runTest( ) { echo "env.DISPLAY is ${env.DISPLAY}" } } - for (int i = 1; i <= ITERATIONS; i++) { - echo "ITERATION: ${i}/${ITERATIONS}" - if (env.SPEC.contains('linux') && !(LABEL.contains('ci.agent.dynamic') && CLOUD_PROVIDER == 'azure') && (BUILD_LIST != "external")) { - // Add an additional 10 second timeout due to issue: https://github.com/adoptium/temurin-build/issues/2368#issuecomment-756683888 - wrap([$class: 'Xvfb', autoDisplayName: true, timeout:20]) { - def DISPLAY = sh ( - script: 'ps -f | grep \'[X]vfb\' | awk \'{print \$9}\'', - returnStdout: true - ).trim() - env.DISPLAY = "${DISPLAY}" - echo "env.DISPLAY is ${env.DISPLAY}" - makeTest("${RUNTEST_CMD}") + try { + boolean wasAborted = false + for (int i = 1; i <= ITERATIONS; i++) { + echo "ITERATION: ${i}/${ITERATIONS}" + echo "currentBuild.result: ${currentBuild.result}" + if (currentBuild.result == 'ABORTED') { + echo "Build is aborted. Stop the loop...." + break + } + if (env.SPEC.contains('linux') && !(LABEL.contains('ci.agent.dynamic') && CLOUD_PROVIDER == 'azure') && (BUILD_LIST != "external")) { + // Add an additional 10 second timeout due to issue: https://github.com/adoptium/temurin-build/issues/2368#issuecomment-756683888 + wrap([$class: 'Xvfb', autoDisplayName: true, timeout:20]) { + def DISPLAY = sh ( + script: 'ps -f | grep \'[X]vfb\' | awk \'{print \$9}\'', + returnStdout: true + ).trim() + env.DISPLAY = "${DISPLAY}" + echo "env.DISPLAY is ${env.DISPLAY}" + makeTest("${RUNTEST_CMD}") + } + } else if (BUILD_LIST.contains('external')) { + sshagent (credentials: ["$params.SSH_AGENT_CREDENTIAL"], ignoreMissing: true) { + makeTest("${RUNTEST_CMD}") + } } - } else if (BUILD_LIST.contains('external')) { - sshagent (credentials: ["$params.SSH_AGENT_CREDENTIAL"], ignoreMissing: true) { + else { makeTest("${RUNTEST_CMD}") } } - else { - makeTest("${RUNTEST_CMD}") + } catch (Exception e) { + println("Exception: " + e.toString()) + if (e.toString().contains("FlowInterruptedException")) { + currentBuild.result = 'ABORTED' + } else { + currentBuild.result = 'FAILURE' } - } + + } finally { + if (currentBuild.rawBuild.isInterrupted()) { + println("Parent job is aborted. Aborting any child jobs...") + // Add code to abort child jobs, if any are running + for (child in currentBuild.rawBuild.getDownstreamBuilds()) { + if (child.isBuilding()) { + child.doStop() + } + } + } + } if (params.CODE_COVERAGE) { echo 'Generating Code Coverage Reports...' @@ -815,6 +841,17 @@ def runTest( ) { } } +def handleException(Exception e) { + // Handle exceptions and set build status accordingly + echo "An error occurred: ${e.message}" + if (e.toString().contains("FlowInterruptedException")) { + currentBuild.result = 'ABORTED' + echo "Build aborted by user or another trigger." + } else { + currentBuild.result = 'FAILURE' + } +} + def checkTestResults(results) { if (results.isEmpty()) { return diff --git a/buildenv/jenkins/openjdk_tests b/buildenv/jenkins/openjdk_tests index 64e937b3da..3d45c58bbe 100644 --- a/buildenv/jenkins/openjdk_tests +++ b/buildenv/jenkins/openjdk_tests @@ -414,6 +414,7 @@ timestamps{ } def runTest() { + boolean wasAborted = false try { def retry_count = 0 def sleep_time = 180 @@ -492,12 +493,18 @@ def runTest() { // build result may not be updated correctly at the moment (see https://issues.jenkins.io/browse/JENKINS-56402) // if there is an exception, set currentBuild.result to ABORTED/FAILURE if (e.toString().contains("FlowInterruptedException")) { - currentBuild.result = 'ABORTED' + wasAborted = true + currentBuild.result = 'ABORTED' + echo "Build aborted by user or another trigger." } else { currentBuild.result = 'FAILURE' } } finally { + if (wasAborted) { + currentBuild.result = 'ABORTED' + echo "aborted build." + } if (params.SLACK_CHANNEL) { timeout(time: 5, unit: 'MINUTES') { if (currentBuild.result == 'FAILURE') {