Hi folks,
is there a way for me to get a notification whenever e.g during a workflow transition one of my scriptrunner post function executions fails? A possible workaround I thought of would be to just surround the whole script in a try catch block and send an email whenever it fails, but I'd like that to be my last option.
Regards
HI @ZubatyNos
I have usually added a custom logger in the Jira log4j config to allow Scriptunner to log information separately.
Then in your script you can pick that up to create output in a file for analysis
Logger logit = Logger.getLogger("com.blah.scriptrunner")
logit.info("my trace message")
It's also possible to add email appenders in log4j but I'v not tried that on Jira.
Sending emails isn't too onerous, I have examples of that if you want.
Another option maybe creating a custom event https://support.atlassian.com/jira-cloud-administration/docs/add-a-custom-event/
The fire that event in your catch block e.g. https://community.atlassian.com/t5/Answers-Developer-Questions/is-there-a-simple-way-to-fire-an-event-using-groovy-script/qaq-p/522574
import com.atlassian.jira.component.ComponentAccessor
import groovy.xml.MarkupBuilder
import com.atlassian.jira.mail.Email
import com.atlassian.jira.mail.settings.MailSettings
import com.atlassian.mail.MailException
import org.apache.log4j.Logger
Logger logit = Logger.getLogger("com.blah.eu.logging")
String emailAddress = "blah@blah.com"
String bodytext = buildHTMLBody( )
def title = " Jira & Confluence cloud migration."
//logit.info title
sendEmail(emailAddress, title, bodytext, logit)
String buildHTMLBody() {
def writer = new StringWriter()
def html = new MarkupBuilder(writer)
def greeting = "Hello "
html.html {
head {
title: "Jira & Confluence on Cloud"
}
body(id: "main") {
p {
mkp.yield greeting
}
p {
mkp.yield "This email is to confirm ... "
strong "log.blah.com"
mkp.yield " and "
strong "space.blah.com"
mkp.yield " sites to Atlassian Cloud."
br{}
}
}
}
return (writer.toString())
}
String sendEmail(String emailAddr, String subject, String body, Logger logit) {
// Stop emails being sent if the outgoing mail server gets disabled (useful if you start a script sending emails and need to stop it)
def mailSettings = ComponentAccessor.getComponent(MailSettings)
if (mailSettings?.send()?.disabled) {
logit.error "Your outgoing mail server has been disabled"
return "Your outgoing mail server has been disabled"
}
def mailServer = ComponentAccessor.mailServerManager.defaultSMTPMailServer
if (!mailServer) {
logit.error("Your mail server Object is Null, make sure to set the SMTP Mail Server Settings Correctly on your Server")
return "Failed to Send Mail. No SMTP Mail Server Defined"
}
def email = new Email(emailAddr)
//email.setCc("ch22.jung@samsung.com")
// email.setCc("omair.irshad@cheil.com")
email.setMimeType("text/html")
email.setSubject(subject)
email.setBody(body)
try {
mailServer.send(email)
logit.info("Mail sent")
//"Success"
} catch (MailException e) {
logit.error("Send mail failed with error: ${e.message}")
//" Failed to Send Mail, Check Logs for error")
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.