Reputation: 37782
Jenkins declarative pipelines allow to declare different post stages to be executed. I have something like this:
post {
fixed {
emailext (
... code to send email
)
}
failure {
emailext (
... code to send email
)
}
}
my real code is much longer and exactly duplicate. Does something exist to combine this code together? Something like
post {
fixed || failure {
emailext (
... code to send email
)
}
}
Upvotes: 1
Views: 1000
Reputation: 131
One round about way to do it is to define the code to send email in a function and call the function from both scenarios.
def SendEmail(){
... code to send email
}
post {
fixed {
emailext (
SendEmail()
)
}
failure {
emailext (
SendEmail()
)
}
}
If you're truly looking for a fixed || failure, I'd suggest looking into the when(){} command. https://jenkins.io/blog/2018/04/09/whats-in-declarative/
Upvotes: 1