From 852a07d1b4a177726be0de5a364fc066839359b8 Mon Sep 17 00:00:00 2001 From: madavi Date: Thu, 25 Jul 2019 12:29:19 +0530 Subject: [PATCH] added try catch for pipeline script Change-Id: I8a3cc8c472c67c5dcd7e6b441919438bdc6eef06 Signed-off-by: madavi --- jenkins/ci-pipelines/ci_stage_1.groovy | 9 +++++++-- jenkins/ci-pipelines/ci_stage_3.groovy | 5 +++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/jenkins/ci-pipelines/ci_stage_1.groovy b/jenkins/ci-pipelines/ci_stage_1.groovy index 722f9c9a..ea221cf6 100644 --- a/jenkins/ci-pipelines/ci_stage_1.groovy +++ b/jenkins/ci-pipelines/ci_stage_1.groovy @@ -101,12 +101,13 @@ node("${params.NODE}") { // error("${project} build ${build} failed") } } - catch (caughtError) { + catch(caughtError) { echo 'Exception in stage_1' currentBuild.result = 'FAILURE' } finally { - if((${currentBuild.result} != 'SUCCESS') && (${env.JOB_NAME} == 'daily-stage_4')){ + try { + if((currentBuild.result != 'SUCCESS') && (env.JOB_NAME == 'daily-stage_4')){ emailext ( subject: "[OSM-Jenkins] Job: ${env.JOB_NAME} Build: ${env.BUILD_NUMBER} Result: ${currentBuild.result}", body: """ Check console output at "${env.BUILD_URL}" """, @@ -114,6 +115,10 @@ node("${params.NODE}") { recipientProviders: [culprits()] ) } + } + catch(caughtError) { + echo "Failure in executing email" + } } } diff --git a/jenkins/ci-pipelines/ci_stage_3.groovy b/jenkins/ci-pipelines/ci_stage_3.groovy index 1809d02b..42fbe1ee 100644 --- a/jenkins/ci-pipelines/ci_stage_3.groovy +++ b/jenkins/ci-pipelines/ci_stage_3.groovy @@ -235,7 +235,12 @@ node("${params.NODE}") { repo_base_url = "-u ${params.REPOSITORY_BASE}" } if ( params.DO_STAGE_4 ) { + try { sh "docker stack list |grep \"${container_name_prefix}\"| awk '{ print \$1 }'| xargs docker stack rm" + } + catch (caughtError) { + println("Caught error: docker stack rm failed!") + } } sh """ export PATH=$PATH:/snap/bin -- 2.17.1