From 40b23b8885c7fb44beaa1e253644567a11cc404e Mon Sep 17 00:00:00 2001 From: Vojtech Juranek Date: Wed, 4 Jan 2023 13:38:34 +0100 Subject: [PATCH] DBZ-5974 Use catchError instead of try/finally block For scripted pipelines (on the contrary to declarative pipelines) the build results has to be set manully if try/catch block is uses. As a workaround `catchError` can be used as this step also sets the `currectResult`. See also https://www.jenkins.io/doc/pipeline/steps/workflow-basic-steps/#catcherror-catch-error-and-set-build-result-to-failure --- .../pipelines/build_debezium_images_pipeline.groovy | 6 +++--- .../pipelines/build_debezium_tool_images_pipeline.groovy | 6 +++--- jenkins-jobs/pipelines/deploy_snapshots_pipeline.groovy | 6 +++--- jenkins-jobs/pipelines/prod-release-pipeline.groovy | 6 +++--- jenkins-jobs/pipelines/release-pipeline.groovy | 6 +++--- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/jenkins-jobs/pipelines/build_debezium_images_pipeline.groovy b/jenkins-jobs/pipelines/build_debezium_images_pipeline.groovy index 3328dfd55..79b51ef5e 100644 --- a/jenkins-jobs/pipelines/build_debezium_images_pipeline.groovy +++ b/jenkins-jobs/pipelines/build_debezium_images_pipeline.groovy @@ -138,7 +138,7 @@ def initVersions(username, password) { } node('Slave') { - try { + catchError { stage('Initialize') { dir('.') { deleteDir() @@ -198,7 +198,7 @@ node('Slave') { } } } - } finally { - mail to: params.MAIL_TO, subject: "${env.JOB_NAME} run #${env.BUILD_NUMBER} finished", body: "Run ${env.BUILD_URL} finished with result: ${currentBuild.currentResult}" } + + mail to: params.MAIL_TO, subject: "${env.JOB_NAME} run #${env.BUILD_NUMBER} finished", body: "Run ${env.BUILD_URL} finished with result: ${currentBuild.currentResult}" } diff --git a/jenkins-jobs/pipelines/build_debezium_tool_images_pipeline.groovy b/jenkins-jobs/pipelines/build_debezium_tool_images_pipeline.groovy index ea5fd5b90..70c2e9f15 100644 --- a/jenkins-jobs/pipelines/build_debezium_tool_images_pipeline.groovy +++ b/jenkins-jobs/pipelines/build_debezium_tool_images_pipeline.groovy @@ -7,7 +7,7 @@ DOCKER_CREDENTIALS_ID = 'debezium-dockerhub' QUAYIO_CREDENTIALS_ID = 'debezium-quay' node('Slave') { - try { + catchError { stage('Initialize') { dir('.') { deleteDir() @@ -39,7 +39,7 @@ node('Slave') { sh "PUSH_IMAGES=true TAG=$TAG ./build-tool-images.sh" } } - } finally { - mail to: params.MAIL_TO, subject: "${env.JOB_NAME} run #${env.BUILD_NUMBER} finished", body: "Run ${env.BUILD_URL} finished with result: ${currentBuild.currentResult}" } + + mail to: params.MAIL_TO, subject: "${env.JOB_NAME} run #${env.BUILD_NUMBER} finished", body: "Run ${env.BUILD_URL} finished with result: ${currentBuild.currentResult}" } diff --git a/jenkins-jobs/pipelines/deploy_snapshots_pipeline.groovy b/jenkins-jobs/pipelines/deploy_snapshots_pipeline.groovy index b4e505c37..234eae243 100644 --- a/jenkins-jobs/pipelines/deploy_snapshots_pipeline.groovy +++ b/jenkins-jobs/pipelines/deploy_snapshots_pipeline.groovy @@ -16,7 +16,7 @@ HOME_DIR = '/home/centos' def additionalDirs = [] node('Slave') { - try { + catchError { stage('Initialize') { dir('.') { deleteDir() @@ -66,7 +66,7 @@ node('Slave') { } } } - } finally { - mail to: params.MAIL_TO, subject: "${env.JOB_NAME} run #${env.BUILD_NUMBER} finished", body: "Run ${env.BUILD_URL} finished with result: ${currentBuild.currentResult}" } + + mail to: params.MAIL_TO, subject: "${env.JOB_NAME} run #${env.BUILD_NUMBER} finished", body: "Run ${env.BUILD_URL} finished with result: ${currentBuild.currentResult}" } diff --git a/jenkins-jobs/pipelines/prod-release-pipeline.groovy b/jenkins-jobs/pipelines/prod-release-pipeline.groovy index 3f5a0e9c7..e142508fa 100644 --- a/jenkins-jobs/pipelines/prod-release-pipeline.groovy +++ b/jenkins-jobs/pipelines/prod-release-pipeline.groovy @@ -31,7 +31,7 @@ REMOTE_TARGET = [ ] node('Slave') { - try { + catchError { stage ('Download and setup bacon') { sh """ rm -rf * @@ -94,7 +94,7 @@ node('Slave') { } } } - } finally { - mail to: MAIL_TO, subject: "${JOB_NAME} run #${BUILD_NUMBER} finished", body: "Run ${BUILD_URL} finished with result: ${currentBuild.currentResult}" } + + mail to: MAIL_TO, subject: "${JOB_NAME} run #${BUILD_NUMBER} finished", body: "Run ${BUILD_URL} finished with result: ${currentBuild.currentResult}" } diff --git a/jenkins-jobs/pipelines/release-pipeline.groovy b/jenkins-jobs/pipelines/release-pipeline.groovy index 6e46b64f2..ae83c24f8 100644 --- a/jenkins-jobs/pipelines/release-pipeline.groovy +++ b/jenkins-jobs/pipelines/release-pipeline.groovy @@ -270,7 +270,7 @@ def mvnRelease(repoDir, repoName, branchName, buildArgs = '') { } node('Slave') { - try { + catchError { stage('Validate parameters') { if (!(RELEASE_VERSION ==~ /\d+\.\d+.\d+\.(Final|(Alpha|Beta|CR)\d+)/)) { error "Release version '$RELEASE_VERSION' is not of the required format x.y.z.suffix" @@ -743,7 +743,7 @@ node('Slave') { } } - } finally { - mail to: MAIL_TO, subject: "${JOB_NAME} run #${BUILD_NUMBER} finished", body: "Run ${BUILD_URL} finished with result: ${currentBuild.currentResult}" } + + mail to: MAIL_TO, subject: "${JOB_NAME} run #${BUILD_NUMBER} finished", body: "Run ${BUILD_URL} finished with result: ${currentBuild.currentResult}" }