slack integration code in Jenkinsfile
@@ -25,6 +25,9 @@ node {
])
])
+ try{
+ notifyBuild('STARTED')
+
// Clean workspace before build starts
stage ("Clean Workspace"){
deleteDir()
@@ -59,7 +62,12 @@ node {
}
}
}
-
+ }catch (e){
+ // If there was an exception thrown, the build failed
+ currentBuild.result = "FAILED"
+ notifyBuild(currentBuild.result)
+ throw e
+ }
// test report on the basis of suite and see report from Allure report plugin &
// see test code coverage report from Coverage report Plugin only when suite choice_test_all and choice_test_python
stage ("Test Report"){
@@ -107,6 +115,35 @@ node {
}
allure([includeProperties: false, jdk: '', properties: [], reportBuildPolicy: 'ALWAYS', results: [[path: 'allure/']]])
}
+
+ // Success of failure, always send notifications
+ notifyBuild(currentBuild.result)
+ }
}
}
+
+def notifyBuild(String buildStatus = 'STARTED'){
+ // build status of null means successful
+ buildStatus = buildStatus ?: 'SUCCESSFUL'
+
+ // Default values
+ def colorName = 'RED'
+ def colorCode = '#FF0000'
+ def subject = "${buildStatus}: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'"
+ def summary = "${subject} (${env.BUILD_URL})"
+
+ // Override default values based on build status
+ if (buildStatus == 'STARTED'){
+ color = 'YELLOW'
+ colorCode = '#FFFF00'
+ } else if (buildStatus == 'SUCCESSFUL'){
+ color = 'GREEN'
+ colorCode = '#00FF00'
+ } else{
+ color = 'RED'
+ colorCode = '#FF0000'
+ }
+
+ // Send notifications
+ slackSend (color: colorCode, message: summary)
}
\ No newline at end of file
