Script Runner Escalation Service custom logging

Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 6, 2015

I'm looking to migrate functionality from the Jelly Services to using Script Runner Escalation Service.

What I want to do is send an email directly to assignee without necessarily updating the issue 

I've frankensteined together some code borrowed from the "Send a Custom Email" built in script and the source of the Escalation Service built in script itself to use as additional code in the Escalation Service.

I can get the service to do what I want, but I was hoping I could implement some logging within this additional code.  Any suggestion how to instantiate the correct object to be able to write to the log? 

The EscalationService.groovy includes

import org.apache.log4j.Logger
[...]
class EscalationService implements CannedScript, PluginJob {
   def log = Logger.getLogger(EscalationService.class)

But since I'm not actually defining a class  I'm not sure how else to get a logger object.

Here is what I have so far:

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.mail.Email
import com.atlassian.mail.MailException
import com.atlassian.mail.MailFactory
import com.atlassian.mail.queue.SingleMailQueueItem
import org.apache.log4j.Logger
def mailServerManager = ComponentAccessor.getMailServerManager();
def mailServer = mailServerManager.getDefaultSMTPMailServer();
if (mailServer && ! MailFactory.isSendingDisabled()) {
	def email = new Email( issue.assignee.emailAddress);
	email.setFrom(mailServer.getDefaultFrom())
	email.setSubject("[JIRA] Update needed: " + issue.key + " - " + issue.summary)
	email.setMimeType("text/plain");
	email.setBody("Please update https://myjirainstance.mydomain.com/browse/" + issue.key + " with the following: \n" +
	"* Current status and actions completed \n" + 
	"* Next Steps \n" +
	"* The names of those responsible for those actions, and the estimated date and time of resolution")
	try {
//		log.debug ("Sending mail to ${email.getTo()}")
//		log.debug ("with body ${email.getBody()}")
		SingleMailQueueItem item = new SingleMailQueueItem(email);
		ComponentAccessor.getMailQueue().addItem(item);
		}
	catch (MailException e) {
//		log.warn ("Error sending email", e)
		}
	}
else {
//	log.warn ("No mail server or sending disabled.")
	}

Perhaps @Jamie Echlin [Adaptavist] has an idea?

Note that I'm quite new at Groovy and even java and I probably have no business fiddling with this... but I figure that's how I'll learn.

Thanks

1 answer

1 accepted

0 votes
Answer accepted
Kristian Walker _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 23, 2015

Hi Peter-Dave Sheenan,

The following code snippet below demonstrates what you will need to be able to write out to the atlassian-jira.log file from within your scripts.

 

// Import log4j 
import org.apache.log4j.Logger
import org.apache.log4j.Level

// Set the log level to DEBUG
log.setLevel(Level.DEBUG)

// Some examples of logging statements

// A DEBUG Statement
log.debug("An example Debug statement")

// A INFO Statement
log.info("An example Info statement")

// A Warning Statement
log.warn("An example Warming statement")

// A Error Statement
log.error("An example Error statement")

 

I hope this helps

Kristian

Edward Greathouse April 5, 2019

Hi @Kristian Walker _Adaptavist_ ,

I have the following in my escalation script:

import org.apache.log4j.Level
import org.apache.log4j.Logger


def myLog = Logger.getLogger("com.onresolve.jira.groovy")
myLog.setLevel(Level.DEBUG)

issueInputParameters.setSummary('bannanna')
issueInputParameters.setSkipScreenCheck(true)
myLog.debug("bannana....")


I clicked on "Run Now", but I never see "bannana..." appear in `atlassian-jira.log`. Is there another log file to check?

Kristian Walker _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 5, 2019

Hi Edward,

Have tested your code and can confirm that the code is valid and works on an escalation service for myself. 

Its sounds to me as if your escalation service is not firing as you have an error on one of the fields mentioned below which you are required to configure to add an escalation service.

  • JQL Query
  • As User
  • Interval/CRON Expression

Can you please check if any errors are displayed below the fields when you click the Run Now button and if so can you please fix these before running your escalation service again.

Regards,

Kristian

Peter-Dave Sheehan
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
April 26, 2019

Found this old thread from when I was just getting started... apparently never marked as answered.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events