I recently converted a scripted pipeline into a declarative pipeline but having trouble to get the build failure case in the post section.
For a scripted pipeline, I can easily wrap the pipeline inside a try-catch and have access to the exception object. But not for declarative pipeline like this:
pipeline {
stages {
...
}
post{
failure {
script {
//this is where i need the failure exception detail
handleFailure()
}
}
}
}
Im not sure how to do that, I'm trying getContext() method but it return null . Appreciate any suggestion.