Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Abort child jobs on build interrupt #5718

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 54 additions & 17 deletions buildenv/jenkins/JenkinsfileBase
Original file line number Diff line number Diff line change
@@ -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
9 changes: 8 additions & 1 deletion buildenv/jenkins/openjdk_tests
Original file line number Diff line number Diff line change
@@ -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') {