I have a pipeline with multiple steps, for example:
stage \'dev - compile\'
node(\'master\') {
//do something
}
stage \'test- compile\'
node(\'master\') {
Well, your idea is absolutely correct, you just need to move mail after the catch block or use finally. Examples (in pseudocode):
try {
//code
email = 'success'
} catch(Exception e) {
// error handler: logging
email = 'failure'
}
send email
Or the same approach using the catchError pipeline built-in:
result = 'failure'
catchError { // this catches all exceptions and set the build result
//code
result = 'success' // we will reach this point only if no exception was thrown
}
send result
Or using finally:
try {
//code
} finally {
send email
}