Workflow : how to send a basic "build failed" mail
417 views
Skip to first unread message
Francois Marot
unread,
Sep 9, 2015, 5:24:18 AM9/9/15
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Jenkins Users
Hello all ! I'm playing with Jenkins Workflow and am wondering how I can send a basic mail telling the team the build has failed. What I would really like is something like the "email notification" step with option "" in the classic jobs. Please detail if this must be defined inside a node or outside. I tried the following as a test but it seem to stuck my build... Do I have to put the try/catch inside each and every node() of my workflow ?
try {
node {
sh 'might fail'
}
} catch (e) {
def w =newStringWriter()
e.printStackTrace(newPrintWriter(w))
mail subject: "failed with ${e.message}", to: 'admin@somewhere', body: "Failed: ${w}"throw e
}
Victor Martinez
unread,
Sep 9, 2015, 1:48:58 PM9/9/15
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
body: "Your job failed, please review it ${env.BUILD_URL}.");
}
Cheers
Francois Marot
unread,
Sep 10, 2015, 4:55:18 PM9/10/15
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Jenkins Users
Thanks Victor,
so in fact what worked was creating a new node() {...} block to wrap my whole workflow and inside it I now have a LARGE try / catch and I send the failure mail in the catch block. I did not know I could nest node() {...} blocks but it seems to work.
In the ends, I got this working (syntax might be wrong as I have no jenkins access right now but you have the idea):
node {
try {
node { sh 'might fail 1' }
node { sh 'might fail 2'
Michael Neale
unread,
Sep 14, 2015, 7:42:13 AM9/14/15
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Jenkins Users
Interesting - is there no way to have an on failure handler (perhaps for all steps) vs a per node or global catch/print writer? (whilst it works it seems to be more work for a common enough desire for failure messages, making me think there is probably another way).
Jesse Glick
unread,
Sep 14, 2015, 9:57:06 AM9/14/15
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Jenkins Users
On Monday, September 14, 2015 at 7:42:13 AM UTC-4, Michael Neale wrote:
is there no way to have an on failure handler (perhaps for all steps) vs a per node or global catch/print writer?