Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

is there a simple way to fire an event using groovy script?

Bartek Zukowski July 6, 2016

Hi,

is there a simple way to fire an issue event using Script Runner Escalation Service by giving event's ID? I only managed to find some old examples with deprecated methods that can't be used in latest versions of JIRA and Script Runner.

In my case I just want to fire one of the defined events to catch it by listener so I can send a custom e-mail to some reporters.

I suspect I should use something like EventPublisher.publish(some_event) but how to assign some_event variable with existing event's ID?

An example would be much appreciated.

 

3 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

8 votes
Answer accepted
Bartek Zukowski July 24, 2016

Finally I've used following code. Maybe someone finds it useful in the future.

import com.atlassian.jira.event.issue.IssueEventBundle
import com.atlassian.jira.event.issue.IssueEventManager
import com.atlassian.jira.event.issue.IssueEventBundleFactory
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.issue.IssueEvent
 
Long EVENT_ID = new Long("10500")
def issueManager = ComponentAccessor.getIssueManager()
def user = ComponentAccessor.getUserManager().getUserByName('user_worker')
 
IssueEventManager issueEventM = ComponentAccessor.getIssueEventManager()
IssueEventBundleFactory issueEventFactory = (IssueEventBundleFactory) ComponentAccessor.getComponent(IssueEventBundleFactory.class)
 
IssueEventBundle eventBundle = issueEventFactory.wrapInBundle(new IssueEvent (issue, null, user, EVENT_ID, true))
issueEventM.dispatchEvent(eventBundle)
Mathieu de Lafond August 23, 2016

Well, I sure did ! 

I couldn't find any proper implementation of the EventBundle thing. Thanks a lot for this code, I got my events working fine again.

And thumbs up for all people who post their code once they found a solution smile

Adam White December 20, 2016

I tried using your code but I got an error:  

 

Error
Could not find matching constructor for: com.atlassian.jira.event.issue.IssueEvent(com.atlassian.jira.issue.IssueImpl, null, com.atlassian.jira.user.DelegatingApplicationUser, java.lang.Long, java.lang.Boolean)
groovy.lang.GroovyRuntimeException: Could not find matching constructor for: com.atlassian.jira.event.issue.IssueEvent(com.atlassian.jira.issue.IssueImpl, null, com.atlassian.jira.user.DelegatingApplicationUser, java.lang.Long, java.lang.Boolean)
at Script181.run(Script181.groovy:14)

 

Looks like it doesn't like this line: 

IssueEventBundle eventBundle = issueEventFactory.wrapInBundle(new IssueEvent (issue, null, user, EVENT_ID, true))

 

any ideas?

Bartek Zukowski December 20, 2016

This script still works without any problems in our instance. Make sure that you haven't missed any part of the script... or maybe you are using some old version of Script Runner and/or Jira. We are currently running Script Runner 4.3.15 and JIRA 7.2.1.

Adam White December 21, 2016

My guess is that it is because we are on JIRA 6.4.11 and 6.4 doesnt support that method... any idea how to make it backwards compatible? 

Bartek Zukowski December 21, 2016

Sorry, but I'm not that advanced in groovy. For me it seems that all the necessary elements are available in 6.4:

  • IssueEventBundleFactory is
  • wrapInBundle() also
  • even constructor for IssueEvent looks the same
Kevin Draai November 28, 2017

@Adam White I don't know if you figured it out but for JIRA 6.4.1 API, make sure that the parameters you pass matches the class constructor signature. 

https://docs.atlassian.com/jira/6.4.1/com/atlassian/jira/event/issue/IssueEvent.html

0 votes
Bartek Zukowski July 8, 2016

Hi Adam,

My client wants to set a reminder for reporters to close resolved issues, once a day until they finally close those issues. So the escalation firing an event that is later caught by listener to send a custom e-mail seems like a good option.

I wanted to use Jira Automation plugin to fire an event, but it cannot fire an event properly (at least such an event couldn't be processed by listener because it lacks some parameters).

I want to use events to avoid updating the issue in the history but I just realized that it might be a wrong assumption. Can I successfully fire an event without updating an issue? I mean without changing "updated date"?

Regards,

Bartek

 

P.S. I tried to use your suggestion and wrote something like this:

import com.atlassian.event.api.EventPublisher
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.component.ComponentAccessor
def user = ComponentAccessor.getUserManager().getUserByName('bzukowski')

EventPublisher.publish(new IssueEvent(issue,user,null,null,null,null,10500))

but it doesn't seem to be working and I am only getting:

groovy.lang.MissingMethodException: No signature of method: static 
com.atlassian.event.api.EventPublisher.publish() is applicable for 
argument types: (com.atlassian.jira.event.issue.IssueEvent) values: 
[com.atlassian.jira.event.issue.IssueEvent@65039afe[issue=ZUKU-1,comment=<null>,worklog=<null>,changelog=<null>,eventTypeId=10500,sendMail=true,params={},subtasksUpdated=false]]

	at Script281.run(Script281.groovy:7)

Probably it's something obvious but not for me wink

0 votes
adammarkham
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.
July 7, 2016

Do you want to send an email every time the escalation service is run or only when an issue has been updated via the escalation service? Sure you can use:

eventPublisher.publish(new IssueEvent(...));

But i'm not sure if this is a good solution to your problem.

TAGS
AUG Leaders

Atlassian Community Events