Skip to content

Commit

Permalink
Fix up pipeline stage result setting and exception handling (#1071)
Browse files Browse the repository at this point in the history
* Fix up pipeline stage result setting and exception handling

Signed-off-by: Andrew Leonard <anleonar@redhat.com>

* Fix up pipeline stage result setting and exception handling

Signed-off-by: Andrew Leonard <anleonar@redhat.com>

---------

Signed-off-by: Andrew Leonard <anleonar@redhat.com>
  • Loading branch information
andrew-m-leonard authored Jul 4, 2024
1 parent 9c2c790 commit b575eaa
Showing 1 changed file with 29 additions and 3 deletions.
32 changes: 29 additions & 3 deletions pipelines/build/common/openjdk_build_pipeline.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,21 @@ class Build {

return jdkRepo
}

/*
If the given result is not SUCCESS then set the current stage result and build result accordingly
*/
def setStageResult(String stage, String result) {
if (result != "SUCCESS") {
// Use catchError to issue error message and set build & stage result
context.catchError(buildResult: result, stageResult: result) {
context.error("${stage} not successful, setting stage result to: "+result)
}
} else {
context.println "${stage} result was SUCCESS"
}
}

/*
Run smoke tests, which should block the running of downstream test jobs if there are failures.
If a test job that doesn't exist, it will be created dynamically.
Expand Down Expand Up @@ -355,8 +370,9 @@ class Build {
context.string(name: 'VENDOR_TEST_REPOS', value: vendorTestRepos),
context.string(name: 'VENDOR_TEST_BRANCHES', value: vendorTestBranches),
context.string(name: 'TIME_LIMIT', value: '1')
]
]
currentBuild.result = testJob.getResult()
setStageResult("smoke test", testJob.getResult())
return testJob.getResult()
}
} catch (Exception e) {
Expand Down Expand Up @@ -474,7 +490,7 @@ class Build {
}
}

def testJobParams = [
def testJobParams = [
context.string(name: 'UPSTREAM_JOB_NUMBER', value: "${env.BUILD_NUMBER}"),
context.string(name: 'UPSTREAM_JOB_NAME', value: "${env.JOB_NAME}"),
context.string(name: 'SDK_RESOURCE', value: 'upstream'),
Expand Down Expand Up @@ -507,6 +523,7 @@ class Build {
parameters: testJobParams,
wait: true
currentBuild.result = testJob.getResult()
setStageResult("${testType}", testJob.getResult())
context.node('worker') {
//Copy Taps files from downstream test jobs if files available.
context.sh 'rm -f workspace/target/AQAvitTaps/*.tap'
Expand All @@ -530,6 +547,7 @@ class Build {
}
} catch (Exception e) {
context.println "Failed to execute test: ${e.message}"
currentBuild.result = 'FAILURE'
}
}
return testStages
Expand Down Expand Up @@ -896,6 +914,7 @@ class Build {
} catch (e) {
context.println("Failed to build ${buildConfig.TARGET_OS} installer ${e}")
currentBuild.result = 'FAILURE'
setStageResult("installer", 'FAILURE')
}
}
}
Expand All @@ -922,6 +941,7 @@ class Build {
} catch (e) {
context.println("Failed to build ${buildConfig.TARGET_OS} installer ${e}")
currentBuild.result = 'FAILURE'
setStageResult("sign installer", 'FAILURE')
}
}
}
Expand Down Expand Up @@ -961,6 +981,7 @@ class Build {
// For Windows and Mac verify that all necessary executables are Signed and Notarized(mac)
private void verifySigning() {
if (buildConfig.TARGET_OS == "windows" || buildConfig.TARGET_OS == "mac") {
context.stage('sign verification') {
try {
context.println "RUNNING sign_verification for ${buildConfig.TARGET_OS}/${buildConfig.ARCHITECTURE} ..."

Expand Down Expand Up @@ -990,7 +1011,9 @@ class Build {
} catch (e) {
context.println("Failed to sign_verification for ${buildConfig.TARGET_OS}/${buildConfig.ARCHITECTURE} ${e}")
currentBuild.result = 'FAILURE'
}
setStageResult("sign verification", 'FAILURE')
}
}
}
}

Expand Down Expand Up @@ -2181,6 +2204,7 @@ class Build {
}
} catch (Exception e) {
context.println(e.message)
currentBuild.result = 'FAILURE'
}
}

Expand All @@ -2199,6 +2223,7 @@ class Build {
gpgSign()
} catch (Exception e) {
context.println(e.message)
currentBuild.result = 'FAILURE'
}
}

Expand All @@ -2209,6 +2234,7 @@ class Build {
verifySigning()
} catch (Exception e) {
context.println(e.message)
currentBuild.result = 'FAILURE'
}
}
}
Expand Down

0 comments on commit b575eaa

Please sign in to comment.