In the case of a failed build in my Jenkins Pipeline, I receive an email through the Extended Email plugin. However, when there are syntax errors in the Pipeline, the email is not sent. For example, if I uncomment ensure {} in the code below:
#!/usr/bin/env groovy
pipeline {
agent any
stages {
stage('Preparation') {
steps {
echo 'preparing...'
}
}
}
post {
failure {
mailSend body: 'An error was detected', subject: 'Build Failed', to: '[email protected]'
}
// ensure {}
}
}
Since ensure {} is placed incorrectly, an error occurs:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript:19:9: Unexpected input: '{' @ line 19, column 9.
ensure {
But an email is not sent in the case of a Pipeline syntax error. How can I ensure that I receive an email when there are syntax errors in the Pipeline?