node{
// my code here
try {
// some steps
currentBuild.result = 'SUCCESS'
} catch (Exception err) {
currentBuild.result = 'FAILURE'
mail // email to me if failed
// some clean steps
}
if (currentBuild.result == 'FAILURE') {
// How to exit pipeline ?
}
/*
* other steps here
*/}