From 4f481eb069872d5a49c09e18e1ffa7c5195617da Mon Sep 17 00:00:00 2001 From: Pawel Cieszko Date: Tue, 21 May 2019 15:40:55 +0200 Subject: [PATCH] OLMIS-6037: Added unstable build status for testing failures --- Jenkinsfile | 39 ++++++++++++++++++++++++++++++++------- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 5968819..3423a4f 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -13,6 +13,7 @@ pipeline { options { buildDiscarder(logRotator(numToKeepStr: '15')) disableConcurrentBuilds() + skipStagesAfterUnstable() } environment { COMPOSE_PROJECT_NAME = "template${BRANCH_NAME}" @@ -59,13 +60,25 @@ pipeline { } steps { withCredentials([file(credentialsId: '8da5ba56-8ebb-4a6a-bdb5-43c9d0efb120', variable: 'ENV_FILE')]) { - sh( script: "./ci-buildImage.sh" ) + script { + try { + sh( script: "./ci-buildImage.sh" ) + } + catch (exc) { + currentBuild.result = 'UNSTABLE' + } + } } } post { success { archive 'build/libs/*.jar,build/resources/main/api-definition.html, build/resources/main/ version.properties' } + unstable { + script { + notifyAfterFailure() + } + } failure { script { notifyAfterFailure() @@ -86,10 +99,17 @@ pipeline { steps { withSonarQubeEnv('Sonar OpenLMIS') { withCredentials([string(credentialsId: 'SONAR_LOGIN', variable: 'SONAR_LOGIN'), string(credentialsId: 'SONAR_PASSWORD', variable: 'SONAR_PASSWORD')]) { - sh(script: "./ci-sonarAnalysis.sh") + script { + try { + sh(script: "./ci-sonarAnalysis.sh") - // workaround: Sonar plugin retrieves the path directly from the output - sh 'echo "Working dir: ${WORKSPACE}/build/sonar"' + // workaround: Sonar plugin retrieves the path directly from the output + sh 'echo "Working dir: ${WORKSPACE}/build/sonar"' + } + catch (exc) { + currentBuild.result = 'UNSTABLE' + } + } } } timeout(time: 1, unit: 'HOURS') { @@ -102,6 +122,11 @@ pipeline { } } post { + unstable { + script { + notifyAfterFailure() + } + } failure { script { notifyAfterFailure() @@ -125,9 +150,9 @@ pipeline { def notifyAfterFailure() { BRANCH = "${env.GIT_BRANCH}".trim() if (BRANCH.equals("master") || BRANCH.startsWith("rel-")) { - slackSend color: 'danger', message: "${env.JOB_NAME} - #${env.BUILD_NUMBER} ${env.STAGE_NAME} FAILED (<${env.BUILD_URL}|Open>)" + slackSend color: 'danger', message: "${env.JOB_NAME} - #${env.BUILD_NUMBER} ${env.STAGE_NAME} ${currentBuild.result} (<${env.BUILD_URL}|Open>)" } - emailext subject: "${env.JOB_NAME} - #${env.BUILD_NUMBER} ${env.STAGE_NAME} FAILED", - body: """

${env.JOB_NAME} - #${env.BUILD_NUMBER} ${env.STAGE_NAME} FAILED

Check console output to view the results.

""", + emailext subject: "${env.JOB_NAME} - #${env.BUILD_NUMBER} ${env.STAGE_NAME} ${currentBuild.result}", + body: """

${env.JOB_NAME} - #${env.BUILD_NUMBER} ${env.STAGE_NAME} ${currentBuild.result}

Check console output to view the results.

""", recipientProviders: [[$class: 'CulpritsRecipientProvider'], [$class: 'DevelopersRecipientProvider']] }