Skip to content

Commit

Permalink
OLMIS-6037: Added unstable build status for testing failures
Browse files Browse the repository at this point in the history
  • Loading branch information
pawelcieszko committed May 21, 2019
1 parent 3ac0b95 commit 4f481eb
Showing 1 changed file with 32 additions and 7 deletions.
39 changes: 32 additions & 7 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pipeline {
options {
buildDiscarder(logRotator(numToKeepStr: '15'))
disableConcurrentBuilds()
skipStagesAfterUnstable()
}
environment {
COMPOSE_PROJECT_NAME = "template${BRANCH_NAME}"
Expand Down Expand Up @@ -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()
Expand All @@ -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') {
Expand All @@ -102,6 +122,11 @@ pipeline {
}
}
post {
unstable {
script {
notifyAfterFailure()
}
}
failure {
script {
notifyAfterFailure()
Expand All @@ -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: """<p>${env.JOB_NAME} - #${env.BUILD_NUMBER} ${env.STAGE_NAME} FAILED</p><p>Check console <a href="${env.BUILD_URL}">output</a> to view the results.</p>""",
emailext subject: "${env.JOB_NAME} - #${env.BUILD_NUMBER} ${env.STAGE_NAME} ${currentBuild.result}",
body: """<p>${env.JOB_NAME} - #${env.BUILD_NUMBER} ${env.STAGE_NAME} ${currentBuild.result}</p><p>Check console <a href="${env.BUILD_URL}">output</a> to view the results.</p>""",
recipientProviders: [[$class: 'CulpritsRecipientProvider'], [$class: 'DevelopersRecipientProvider']]
}

0 comments on commit 4f481eb

Please sign in to comment.