From 9ab3cbb96a536ec3ad5c4b0540953f24bf820266 Mon Sep 17 00:00:00 2001 From: Anna Babu Palathingal <148897727+annaibm@users.noreply.github.com> Date: Thu, 24 Oct 2024 09:48:21 -0400 Subject: [PATCH 1/8] Abort child jobs on build interrupt - Add a check for current build result, to determine if it is aborted. - If the build is aborted, terminate the child jobs by breaking the loop. Signed-off-by: Anna Babu Palathingal --- buildenv/jenkins/JenkinsfileBase | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/buildenv/jenkins/JenkinsfileBase b/buildenv/jenkins/JenkinsfileBase index 24c8b3ec68..98ac6ae3f7 100644 --- a/buildenv/jenkins/JenkinsfileBase +++ b/buildenv/jenkins/JenkinsfileBase @@ -765,6 +765,10 @@ def runTest( ) { } for (int i = 1; i <= ITERATIONS; i++) { echo "ITERATION: ${i}/${ITERATIONS}" + 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]) { From f28005b7fdd5b3fc5d503bb98cbcf5504eb94a5c Mon Sep 17 00:00:00 2001 From: Anna Babu Palathingal <148897727+annaibm@users.noreply.github.com> Date: Thu, 24 Oct 2024 12:14:21 -0400 Subject: [PATCH 2/8] Added echo stmt --- buildenv/jenkins/JenkinsfileBase | 1 + 1 file changed, 1 insertion(+) diff --git a/buildenv/jenkins/JenkinsfileBase b/buildenv/jenkins/JenkinsfileBase index 98ac6ae3f7..78225a8def 100644 --- a/buildenv/jenkins/JenkinsfileBase +++ b/buildenv/jenkins/JenkinsfileBase @@ -765,6 +765,7 @@ def runTest( ) { } 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 From e4e89e7d8dc2826f79800dec0f243568c51afb78 Mon Sep 17 00:00:00 2001 From: Anna Babu Palathingal <148897727+annaibm@users.noreply.github.com> Date: Thu, 24 Oct 2024 14:14:52 -0400 Subject: [PATCH 3/8] added unstable --- buildenv/jenkins/JenkinsfileBase | 58 +++++++++++++++++++------------- 1 file changed, 35 insertions(+), 23 deletions(-) diff --git a/buildenv/jenkins/JenkinsfileBase b/buildenv/jenkins/JenkinsfileBase index 78225a8def..650ee7c550 100644 --- a/buildenv/jenkins/JenkinsfileBase +++ b/buildenv/jenkins/JenkinsfileBase @@ -763,33 +763,45 @@ def runTest( ) { echo "env.DISPLAY is ${env.DISPLAY}" } } - 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}") + try { + for (int i = 1; i <= ITERATIONS; i++) { + echo "ITERATION: ${i}/${ITERATIONS}" + echo "currentBuild.result: ${currentBuild.result}" + if (currentBuild.result == 'ABORTED' || currentBuild.result == 'UNSTABLE') { + 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) { + echo "An error occurred: ${e.message}" + currentBuild.result = 'FAILURE' + } finally { + // Cleanup: Terminate any running processes if the build was aborted + if (currentBuild.result == 'ABORTED') { + echo "Cleaning up any running child jobs due to build being aborted..." + // Implement your logic to abort child processes if necessary + // Example: sh "pkill -f 'your_process_name'" to kill a specific process + } + } if (params.CODE_COVERAGE) { echo 'Generating Code Coverage Reports...' From 1149bf1e9bea6817eef3d7bd2036b9f28da78691 Mon Sep 17 00:00:00 2001 From: Anna Babu Palathingal <148897727+annaibm@users.noreply.github.com> Date: Mon, 28 Oct 2024 09:02:42 -0400 Subject: [PATCH 4/8] Added check to aborted in runTests --- buildenv/jenkins/JenkinsfileBase | 2 +- buildenv/jenkins/openjdk_tests | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/buildenv/jenkins/JenkinsfileBase b/buildenv/jenkins/JenkinsfileBase index 650ee7c550..09aaeb231f 100644 --- a/buildenv/jenkins/JenkinsfileBase +++ b/buildenv/jenkins/JenkinsfileBase @@ -767,7 +767,7 @@ def runTest( ) { for (int i = 1; i <= ITERATIONS; i++) { echo "ITERATION: ${i}/${ITERATIONS}" echo "currentBuild.result: ${currentBuild.result}" - if (currentBuild.result == 'ABORTED' || currentBuild.result == 'UNSTABLE') { + if (currentBuild.result == 'ABORTED') { echo "Build is aborted. Stop the loop...." break } diff --git a/buildenv/jenkins/openjdk_tests b/buildenv/jenkins/openjdk_tests index 64e937b3da..6cb7fb5b4a 100644 --- a/buildenv/jenkins/openjdk_tests +++ b/buildenv/jenkins/openjdk_tests @@ -491,13 +491,18 @@ def runTest() { println("Exception: " + e.toString()) // 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")) { + if (e.toString().contains("FlowInterruptedException") || currentBuild.rawBuild.getExecutor()?.isInterrupted()) { currentBuild.result = 'ABORTED' + echo "Build aborted by user or another trigger." } else { currentBuild.result = 'FAILURE' } } finally { + if (currentBuild.rawBuild.getExecutor()?.isInterrupted()) { + currentBuild.result = 'ABORTED' + echo "Build aborted by user or another trigger." + } if (params.SLACK_CHANNEL) { timeout(time: 5, unit: 'MINUTES') { if (currentBuild.result == 'FAILURE') { From af148627059dd8332bed8d31d90eb961b6b2ff8f Mon Sep 17 00:00:00 2001 From: Anna Babu Palathingal <148897727+annaibm@users.noreply.github.com> Date: Mon, 28 Oct 2024 09:46:03 -0400 Subject: [PATCH 5/8] Added flag to abort build --- buildenv/jenkins/openjdk_tests | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/buildenv/jenkins/openjdk_tests b/buildenv/jenkins/openjdk_tests index 6cb7fb5b4a..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 @@ -491,17 +492,18 @@ def runTest() { println("Exception: " + e.toString()) // 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.rawBuild.getExecutor()?.isInterrupted()) { - currentBuild.result = 'ABORTED' + if (e.toString().contains("FlowInterruptedException")) { + wasAborted = true + currentBuild.result = 'ABORTED' echo "Build aborted by user or another trigger." } else { currentBuild.result = 'FAILURE' } } finally { - if (currentBuild.rawBuild.getExecutor()?.isInterrupted()) { + if (wasAborted) { currentBuild.result = 'ABORTED' - echo "Build aborted by user or another trigger." + echo "aborted build." } if (params.SLACK_CHANNEL) { timeout(time: 5, unit: 'MINUTES') { From c6d404f52aa5149fc0fe35c3db39c547a9574f33 Mon Sep 17 00:00:00 2001 From: Anna Babu Palathingal <148897727+annaibm@users.noreply.github.com> Date: Tue, 29 Oct 2024 11:32:13 -0400 Subject: [PATCH 6/8] added was Aborted status flag --- buildenv/jenkins/JenkinsfileBase | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/buildenv/jenkins/JenkinsfileBase b/buildenv/jenkins/JenkinsfileBase index 09aaeb231f..eefa2c075c 100644 --- a/buildenv/jenkins/JenkinsfileBase +++ b/buildenv/jenkins/JenkinsfileBase @@ -764,6 +764,7 @@ def runTest( ) { } } try { + boolean wasAborted = false for (int i = 1; i <= ITERATIONS; i++) { echo "ITERATION: ${i}/${ITERATIONS}" echo "currentBuild.result: ${currentBuild.result}" @@ -793,14 +794,20 @@ def runTest( ) { } } catch (Exception e) { echo "An error occurred: ${e.message}" - currentBuild.result = 'FAILURE' + if (e.toString().contains("FlowInterruptedException")) { + wasAborted = true + currentBuild.result = 'ABORTED' + echo "Build aborted by user or another trigger." + } else { + currentBuild.result = 'FAILURE' + } } finally { // Cleanup: Terminate any running processes if the build was aborted - if (currentBuild.result == 'ABORTED') { - echo "Cleaning up any running child jobs due to build being aborted..." - // Implement your logic to abort child processes if necessary - // Example: sh "pkill -f 'your_process_name'" to kill a specific process - } + if (wasAborted || currentBuild.result == 'ABORTED') { + echo "Cleaning up any running child jobs due to build being aborted..." + // Add logic to abort child processes if necessary + // Example: sh "pkill -f 'your_process_name'" + } } if (params.CODE_COVERAGE) { From f4909f436d79e1c7cdee2c0cf638a8748be547a6 Mon Sep 17 00:00:00 2001 From: Anna Babu Palathingal <148897727+annaibm@users.noreply.github.com> Date: Tue, 29 Oct 2024 12:46:59 -0400 Subject: [PATCH 7/8] Added the exception e --- buildenv/jenkins/JenkinsfileBase | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/buildenv/jenkins/JenkinsfileBase b/buildenv/jenkins/JenkinsfileBase index eefa2c075c..a558d1a5c4 100644 --- a/buildenv/jenkins/JenkinsfileBase +++ b/buildenv/jenkins/JenkinsfileBase @@ -793,14 +793,7 @@ def runTest( ) { } } } catch (Exception e) { - echo "An error occurred: ${e.message}" - if (e.toString().contains("FlowInterruptedException")) { - wasAborted = true - currentBuild.result = 'ABORTED' - echo "Build aborted by user or another trigger." - } else { - currentBuild.result = 'FAILURE' - } + handleException(e) } finally { // Cleanup: Terminate any running processes if the build was aborted if (wasAborted || currentBuild.result == 'ABORTED') { @@ -839,6 +832,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 From c12b14543d01d7bb497a043b127f49eb72f16a69 Mon Sep 17 00:00:00 2001 From: Anna Babu Palathingal <148897727+annaibm@users.noreply.github.com> Date: Fri, 1 Nov 2024 09:30:27 -0400 Subject: [PATCH 8/8] added change to check child job abort --- buildenv/jenkins/JenkinsfileBase | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/buildenv/jenkins/JenkinsfileBase b/buildenv/jenkins/JenkinsfileBase index a558d1a5c4..f1564ad02f 100644 --- a/buildenv/jenkins/JenkinsfileBase +++ b/buildenv/jenkins/JenkinsfileBase @@ -793,14 +793,23 @@ def runTest( ) { } } } catch (Exception e) { - handleException(e) - } finally { - // Cleanup: Terminate any running processes if the build was aborted - if (wasAborted || currentBuild.result == 'ABORTED') { - echo "Cleaning up any running child jobs due to build being aborted..." - // Add logic to abort child processes if necessary - // Example: sh "pkill -f 'your_process_name'" - } + 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) {