Jenkins declarative pipeline post always condition throws error in logs

755 views Asked by At

I am using a declarative pipeline with post conditions & it sends email as expected. However in case of a failure in any stages it does not shows the actual error in the logs instead it gives below error. there is no issues with emails i received everytime. Any idea ow to catch the actual error?

[Pipeline] End of Pipeline Also:
groovy.lang.MissingPropertyException: No such property: err for class: groovy.lang.Binding at groovy.lang.Binding.getVariable(Binding.java:63)

this is my post condition

post {
       always {emailext (
              body: """
              <html>
              </html>
              """,
              subject: "jenkins-CICD build ${env.JOB_BASE_NAME} #${env.BUILD_NUMBER} is ${currentBuild.result}", 
              mimeType: 'text/html', 
              to: '[email protected]')}
            }
1

There are 1 answers

1
Michael Kemmerzell On BEST ANSWER

A simple try-catch should work.

post { 
     always {
        try {
             emailext (...)
        } catch (error) { 
          // ignore error
        }
     }
}