jobs/Common,BuildAll: integrated Abort handling

if the nightly job is aborted any downstream job are aborted and
no further build target job is triggered. I case of an exception
the job is handled as failed with the note of exception but no
longer an error is thrown.
To get the handling properly done, the nightly triggers downstream
jobs with propagate flag set to false. The result handling is done
with <job>.getResult() and catching exceptions.

Signed-off-by: Marc Mattmüller <marc.mattmueller@netmodule.com>
This commit is contained in:
Marc Mattmüller 2023-09-12 11:55:38 +02:00
parent 652739e0f0
commit 6c83d053c8
2 changed files with 30 additions and 11 deletions

View File

@ -134,7 +134,7 @@ def runUpdateSrcRevJob(commonHelpers, buildBranch, isCleanRequested, isDryRun) {
try { try {
updateJob = build(job: "${env.SRCREV_JOB}", updateJob = build(job: "${env.SRCREV_JOB}",
quietPeriod: 0, quietPeriod: 0,
propagate: true, propagate: false,
wait: true, wait: true,
parameters: [string(name: 'BUILD_BRANCH', value: buildBranch), parameters: [string(name: 'BUILD_BRANCH', value: buildBranch),
booleanParam(name: 'CLEAN_BUILD', value: isCleanRequested), booleanParam(name: 'CLEAN_BUILD', value: isCleanRequested),
@ -143,7 +143,6 @@ def runUpdateSrcRevJob(commonHelpers, buildBranch, isCleanRequested, isDryRun) {
} }
catch(Exception e) { catch(Exception e) {
error("Exception: " + e.toString()) error("Exception: " + e.toString())
return
} }
// assert to be sure // assert to be sure
if(updateJob == null) { if(updateJob == null) {
@ -181,11 +180,12 @@ def isMachineSane(machine) {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
def runBuildJob(commonHelpers, buildTarget, buildBranch) { def runBuildJob(commonHelpers, buildTarget, buildBranch) {
def buildJob = null def buildJob = null
Boolean isSuccessfullyBuilt = true def theBuildResult = 'SUCCESS'
Boolean hasException = false
try { try {
buildJob = build(job: "${env.BUILD_JOB}", buildJob = build(job: "${env.BUILD_JOB}",
quietPeriod: 0, quietPeriod: 0,
propagate: true, propagate: false,
wait: true, wait: true,
parameters: [string(name: 'TARGET', value: buildTarget), parameters: [string(name: 'TARGET', value: buildTarget),
string(name: 'BUILD_BRANCH', value: buildBranch), string(name: 'BUILD_BRANCH', value: buildBranch),
@ -196,17 +196,26 @@ def runBuildJob(commonHelpers, buildTarget, buildBranch) {
booleanParam(name: 'DEBUGGING', value: params.DEBUGGING)] booleanParam(name: 'DEBUGGING', value: params.DEBUGGING)]
) )
} }
catch (org.jenkinsci.plugins.workflow.steps.FlowInterruptedException e) {
println "job ${env.BUILD_JOB} for TARGET=${buildTarget} was cancelled or aborted"
theBuildResult = 'ABORTED'
}
catch(Exception e) { catch(Exception e) {
error("Exception: " + e.toString()) hasException = true
return theBuildResult = 'FAILURE'
println "Exception caught: " + e.toString()
}
finally {
if(!hasException && (buildJob != null)) {
theBuildResult = buildJob.getResult()
}
return theBuildResult
} }
// assert to be sure // assert to be sure
if(buildJob == null) { if(buildJob == null) {
error("Something went really wrong with ${env.BUILD_JOB} (TARGET=${buildTarget})") error("Something went really wrong with ${env.BUILD_JOB} (TARGET=${buildTarget})")
return
} }
isSuccessfullyBuilt = (buildJob.getResult() == 'SUCCESS') return buildJob.getResult()
return isSuccessfullyBuilt
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
def buildMachine(commonHelpers, machine, buildBranch) { def buildMachine(commonHelpers, machine, buildBranch) {
@ -215,7 +224,13 @@ def buildMachine(commonHelpers, machine, buildBranch) {
// NOTE: this catchError statement is needed in case of an // NOTE: this catchError statement is needed in case of an
// abort of the build job or similar failures // abort of the build job or similar failures
catchError(buildResult: 'UNSTABLE', stageResult: 'FAILURE') { catchError(buildResult: 'UNSTABLE', stageResult: 'FAILURE') {
isMachineSuccessfullyBuilt = runBuildJob(commonHelpers, machine, buildBranch) def buildJobStatus = runBuildJob(commonHelpers, machine, buildBranch)
if(buildJobStatus != 'SUCCESS') {
isMachineSuccessfullyBuilt = false
if(buildJobStatus == 'ABORTED') {
currentBuild.result = 'ABORTED'
}
}
} }
if(!isMachineSuccessfullyBuilt) { if(!isMachineSuccessfullyBuilt) {
println "Failed building properly machine ${machine}" println "Failed building properly machine ${machine}"
@ -231,7 +246,7 @@ def buildAllTargets(commonHelpers, buildBranch) {
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') { catchError(buildResult: 'FAILURE', stageResult: 'FAILURE') {
for (machine in listOfTargets) { for (machine in listOfTargets) {
if(isMachineSane(machine)) { if(!commonHelpers.isCurrentJobAborted() && isMachineSane(machine)) {
Boolean isMachineSuccess = buildMachine(commonHelpers, machine, buildBranch) Boolean isMachineSuccess = buildMachine(commonHelpers, machine, buildBranch)
if(!isMachineSuccess && areBuildsSuccessful) { if(!isMachineSuccess && areBuildsSuccessful) {
areBuildsSuccessful = false areBuildsSuccessful = false

View File

@ -74,6 +74,10 @@ def isCurrentJobSuccess() {
return (currentBuild.currentResult == 'SUCCESS') return (currentBuild.currentResult == 'SUCCESS')
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
def isCurrentJobAborted() {
return ((currentBuild.currentResult == 'ABORTED') || (currentBuild.result == 'ABORTED'))
}
//-----------------------------------------------------------------------------
def cleaningClonedRepoDir() { def cleaningClonedRepoDir() {
println "cleaning the entire repository..." println "cleaning the entire repository..."
sh("git clean -ffdx") sh("git clean -ffdx")