In this example we want to create a simple Listener for Jira to reopen issues when are closed/done and someone comments the ticket.
Imagine, we have a ticket in status “DONE”
And there is a “new comment”. Then, the Listener must reopen the issue, and the ticket becomes in “TO DO” status.
In this example, we can use plugins like Adaptavist Scriptrunner or Groovy Amigo. In this case we will take a look into “Groovy Amigo“. (see more)
For the listener we will go to “Groovy Listeners” section in Jira System panel (once installed Groovy Amigo)
And we will create the new listener: (In Event “Issue Commented” and for project X)
with the code
import com.atlassian.jira.issue.Issue; import org.apache.log4j.Category; import com.atlassian.jira.component.ComponentAccessor import com.opensymphony.workflow.WorkflowContext; import com.atlassian.jira.workflow.WorkflowTransitionUtil; import com.atlassian.jira.workflow.WorkflowTransitionUtilImpl; import com.atlassian.jira.util.JiraUtils; import com.atlassian.jira.issue.comments.CommentManager; import com.atlassian.jira.issue.link.IssueLink; import com.atlassian.jira.issue.MutableIssue; Issue issue = event.issue if (issue.getStatusObject().getName()=="Done") { WorkflowTransitionUtil workflowTransitionUtil = ( WorkflowTransitionUtil ) JiraUtils.loadComponent( WorkflowTransitionUtilImpl.class ); workflowTransitionUtil.setIssue((MutableIssue) issue) workflowTransitionUtil.setUserkey("admin") workflowTransitionUtil.setAction(51) workflowTransitionUtil.validate(); workflowTransitionUtil.progress(); }
We will need to change the action for the right ID of the transition. The same for the username who will execute the transition, and the name of the final status.
And now… just try! comment some issue and will be reopened!
By MrAddon
Hi.
I was wondering if its possible to add a script file to an listener with it importing multiple custom classes part of a package?
Apologies if this is the wrong place to ask.
Thanks
LikeLike
Hi,
I see in my installation that you can load a class in the Listener, but I do not see place to load a file script as execution code for the Listener (like in Adaptavist Scriptrunner). There is very few documentation of MyGroovy plugin (is Open Source) https://my-com.atlassian.net/wiki/spaces/GROOVY/pages/435224577/Loading+classes+and+services
Best regards!
LikeLike