Aman
Aman

Reputation: 367

Mail to send from Jenkinsfile everytime there is a build

I am using Jenkinsfile to do build and send mail. Problem is my mail functionality is working when build status gets changed i.e. success to fail and fail to success. I want every time it should shoot mail when build is completed.

 stage('Mail'){
    currentBuild.result = "SUCCESS"
    step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: '[email protected]', sendToIndividuals: true])
  }
}
catch (err) {
    currentBuild.result = "FAILURE"
        step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: '[email protected]', sendToIndividuals: true])
    throw err
}
finally{
    if(currentBuild.result=='SUCCESS'){

    }
}

I tried to find few solutions, but was unsuccessful. Aman

Upvotes: 0

Views: 708

Answers (1)

Sam
Sam

Reputation: 2882

Putting the code in the finally block without the If check will cause the Mailer step to fire regardless of build result.

Upvotes: 1

Related Questions