Skip to content

Commit

Permalink
Fix function for slack notification
Browse files Browse the repository at this point in the history
Signed-off-by: Pablo Iranzo Gómez <Pablo.Iranzo@gmail.com>
  • Loading branch information
iranzo committed Nov 6, 2019
1 parent c72d857 commit d500a12
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,30 @@ def cloudEnvironments = [
// ]
]

def call(String buildResult) {
if ( buildResult == "SUCCESS" ) {
slackSend color: "good", message: "Job: ${env.JOB_NAME} with buildnumber ${env.BUILD_NUMBER} was successful"
}
else if( buildResult == "FAILURE" ) {
slackSend color: "danger", message: "Job: ${env.JOB_NAME} with buildnumber ${env.BUILD_NUMBER} was failed"
}
else if( buildResult == "UNSTABLE" ) {
slackSend color: "warning", message: "Job: ${env.JOB_NAME} with buildnumber ${env.BUILD_NUMBER} was unstable"
}
else {
slackSend color: "danger", message: "Job: ${env.JOB_NAME} with buildnumber ${env.BUILD_NUMBER} its resulat was unclear"
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)
}

builders = [:]
Expand Down Expand Up @@ -127,7 +138,7 @@ cloudEnvironments.each { environName, environValues ->

} finally {
/* Use slackNotifier.groovy from shared library and provide current build result as parameter */
slackNotifier(currentBuild.currentResult)
notifyBuild(currentBuild.result)
}
// END try/catch

Expand Down

0 comments on commit d500a12

Please sign in to comment.