Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Email Failed Scriptrunner jobs everyday

anil musunuru
Contributor
December 19, 2023

There are some scheduled Scriptrunner Jobs which run everyday, if it fails need to send email with details of failed job, how do we do it using Listeners or what is the right way to do it, there are many scheduled Jobs which need to be monitored and sent email when the executions have failed.IMG_3474.jpg

4 answers

0 votes
Ram Kumar Aravindakshan _Adaptavist_
Community Champion
December 22, 2023

Hi @anil musunuru

Could you please clarify what is the current version of Jira you are using?

I am asking for this to verify if the solution provided by @Sean Chua _Adaptavist_ is applicable to your environment.

Also, if the version of Jira you are using is 8.20 and above, it would be best to update your ScriptRunner plugin to the latest release so you can make use of ScriptRunner'S HAPI feature which can simplify the process of the email notification.

I am looking forward to your feedback and clarification.

Thank you and Kind regards,

Ram

0 votes
Sean Chua _Adaptavist_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 19, 2023

Hey @anil musunuru , following on from what Peter said - what version of ScriptRunner are you on? 

Execution failure notifier is a built-in script available from ScriptRunner for Jira Server/Data Center v8.5x onwards.

If you are using the right ScriptRunner version, you can find it in your "Listeners" tab, right at the top.

image.png

If you've upgraded to the latest ScriptRunner version, you can now get example scripts directly from the editor;

image.png

Examples;

image.png

If you don't have the latest version.. I've copied the script for you - maybe you can test this out;

import com.atlassian.mail.queue.SingleMailQueueItem
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.mail.Email

def email = new Email('user@email.com')
email.setSubject("Something has gone wrong in ${event.featureName}")
email.setBody("""
Notes: ${event.notes}.
Something has gone wrong in ${event.featureName}.
To edit this click here: ${event.url}

Error: ${event.stackTrace}
""")

SingleMailQueueItem item = new SingleMailQueueItem(email)
ComponentAccessor.getMailQueue().addItem(item)

anil musunuru
Contributor
December 20, 2023

Thanks for sending the Code snippet, will try and let you know, i am using Scriptrunner version 6.49.0 

0 votes
PD Sheehan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 19, 2023

Have you tried this:

https://docs.adaptavist.com/sr4js/latest/features/listeners/built-in-listeners/execution-failure-notifier

One of the code examples includes how to send an email.

anil musunuru
Contributor
December 19, 2023

I’m using Jira Software and i dont see an option for Execution Failure Notifier.

0 votes
anil musunuru
Contributor
December 19, 2023

Suggest an answer

Log in or Sign up to answer