From 29b871ef81b96fe03f31ff32d63063306711d271 Mon Sep 17 00:00:00 2001 From: Pawel Cieszko Date: Tue, 21 May 2019 14:50:25 +0200 Subject: [PATCH] OLMIS-6037: Added unstable build status for testing failures --- Jenkinsfile | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 2ee906f..cbb3673 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -13,6 +13,7 @@ pipeline { options { buildDiscarder(logRotator(numToKeepStr: '15')) disableConcurrentBuilds() + skipStagesAfterUnstable() } environment { COMPOSE_PROJECT_NAME = "auth${BRANCH_NAME}" @@ -62,13 +63,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() @@ -125,10 +138,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') { @@ -141,6 +161,11 @@ pipeline { } } post { + unstable { + script { + notifyAfterFailure() + } + } failure { script { notifyAfterFailure() @@ -237,9 +262,9 @@ pipeline { def notifyAfterFailure() { BRANCH = "${BRANCH_NAME}" 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']] -} \ No newline at end of file +}