Email only after all retries fail

471 views
Skip to first unread message

Harpel, Craig

unread,
Aug 5, 2014, 4:44:46 PM8/5/14
to jenkins...@googlegroups.com

I’m trying to get Jenkins to send email to recipients only after the last attempted retry of a job fails.  In other words, I don’t want them getting email for all the failures; just if they *all* fail.  Is there a way to do that with the email-ext plugin and naginator?

 

Thanks.

Craig

 

Slide

unread,
Aug 5, 2014, 5:24:55 PM8/5/14
to Jenkins User Mailing List
How do you determine if the job will be the last attempt? If there is something in the environment or something like that which tells you it is the last attempt, you could use a pre-send script to cancel sending the email unless that condition was met.


--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Website: http://earl-of-code.com

Harpel, Craig

unread,
Aug 5, 2014, 5:41:45 PM8/5/14
to jenkins...@googlegroups.com

Naginator knows the last attempt, because it knows when to give up.

What I’m asking is whether there is any integration between Naginator and one of the email plugins that will let me do this without writing scripts.  It sounds like the answer is “no”.

Slide

unread,
Aug 5, 2014, 9:06:34 PM8/5/14
to Jenkins User Mailing List

There currently is not, but email-ext had an extension point for triggers, so someone could implement a trigger for naginator that only sent on the last attempt.

Jarvis

unread,
Apr 20, 2015, 2:16:58 PM4/20/15
to jenkins...@googlegroups.com
@Craig

Have you figured out a way to access the retry number from a groovy script? I'm having the same exact problem you're having with naginator and the email plugin. Since I'm not sure how to stop the email from going out, my idea was to set the recipient only when it's fails and is on the last retry number.

Илья Ефимов

unread,
May 23, 2016, 11:34:40 AM5/23/16
to Jenkins Users
Hi. I also have same problem and with latest (1.17 - Mar 12, 2016) version of naginator it seems can be solved with NAGINATOR_COUNT, NAGINATOR_MAXCOUNT, NAGINATOR_BUILD_NUMBER variables. But I have no idea how to make it working. For example my non-working script:
def ngc = System.getenv("NAGINATOR_COUNT")
def ngmc = System.getenv("NAGINATOR_MAXCOUNT")
cancel = (ngc!=ngmc)

Michal Kubenka

unread,
Jun 15, 2016, 6:13:17 PM6/15/16
to Jenkins Users
Try this:

// You need some different default values so it won't be a null
def retryCount = build.envVars['NAGINATOR_COUNT'] ?: 0
def retryMaxCount = build.envVars['NAGINATOR_MAXCOUNT'] ?: 1

retryCount == retryMaxCount

ram g

unread,
Jan 26, 2017, 4:10:54 PM1/26/17
to Jenkins Users
Hi Michal,

I have used below script, but Still email gets triggered for all builds-


def retryCount = build.envVars['NAGINATOR_COUNT'] ?: 0;
def retryMaxCount = build.envVars['NAGINATOR_MAXCOUNT'] ?: 3;
retryCount == retryMaxCount

Sandeep R Kurup

unread,
May 5, 2018, 5:57:41 AM5/5/18
to Jenkins Users
hey if in case you are still facing the issue,

You can use jenkins Editable Email Notification plugin and in advanced settings you will have an option of failure-X where you can specify after how many failures you need to send the email. Old versions of jenkins may not be helping with this. So you can use the following PRESEND SCRIPT in editable email-notification


try { //used try catch because NAGINATOR_COUNT will be a undefined property for first build
cancel = true
if ($NAGINATOR_COUNT && $NAGINATOR_COUNT == 2) { //where after 2nd retry it will trigger email
 cancel = false
}
} catch (e) {
 cancel = true
}

Hope this answers
Reply all
Reply to author
Forward
0 new messages