1
votes

I have installed the pipeline declarative version 1.3.9 and i integrated the slack plugin to send result when pipeline finish. If I see on jenkins I can see that the build is failed but the message i have on slack is success.

This is the pipeline snippet i use to post on slack

def COLOR_MAP = ['SUCCESS': 'good', 'FAILURE': 'danger', 'UNSTABLE': 'danger', 'ABORTED': 'danger']

slackSend channel: '#jenkins',
                            color: COLOR_MAP[currentBuild.currentResult],
                            message: "*${currentBuild.currentResult}:* Job ${env.JOB_NAME} build ${env.BUILD_NUMBER} \n More info at: ${env.BUILD_URL}"

what can i do to solve the problem?

edit:

post {
        failure {
            slackSend channel: '#jenkins',
                                color: 'danger',
                                message: "*${currentBuild.currentResult}:* Job ${env.JOB_NAME} build ${env.BUILD_NUMBER} - Env ${params.deployEnvironment} \n More info at: ${env.BUILD_URL}"
        }
        success {
            slackSend channel: '#jenkins',
                                    color: COLOR_MAP[currentBuild.currentResult],
                                    message: "*${currentBuild.currentResult}:* Job ${env.JOB_NAME} build ${env.BUILD_NUMBER} \n More info at: ${env.BUILD_URL}"
        }
    }

even if I do this I have two slack notification in case of failure

1
The build may have failed after sending the Slack notification.Matt Schuchard
the slack notification is in post "stage". i tryed to add post failure and post success. even if it fails it enter in bothLuca
Anyone can help me?Luca

1 Answers

0
votes

You can use the currentBuild.result instead of currentBuild.currentResult.

pipeline{
agent any
stages {
    stage('init'){
       steps{ echo "init" }
    }
 }
post {
     success {
        echo "sucess ${currentBuild.result}"
     }
     failure { 
        echo "Failure ${currentBuild.result}" 
     }
  }
}