I'm using Jamie Echlin's Script Runner plugin, and I'm trying to set up a script that will fire an event if an issue is created with a priority of "Emergency". This event will then be picked up by the event listener, and I've got a notification scheme set up to send an email to a particular email address when the event gets fired.
Here's the script I'm using, based on (actually exactly) Jamie's example:
import com.atlassian.jira.ManagerFactory import com.atlassian.jira.event.issue.IssueEventDispatcher import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.comments.Comment import org.apache.log4j.Category import org.ofbiz.core.entity.GenericValue import com.atlassian.jira.event.issue.IssueEventSource log = Category.getInstance("com.onresolve.jira.groovy.example.SendEmailOnBlocker") if (issue.getPriorityObject().getName().equals("Blocker")) { // check if the priority is Blocker, change this line for other criteria Issue updatedIssue = (Issue) transientVars.get("issue"); Comment comment = (Comment)transientVars.get("commentValue"); GenericValue changeGroup = (GenericValue) transientVars.get("changeGroup"); Map params = new HashMap(4); params.put("eventsource", IssueEventSource.WORKFLOW); IssueEventDispatcher.dispatchEvent(10000, updatedIssue, ManagerFactory.getWorkflowManager().getRemoteUser(transientVars), comment, null, changeGroup, params, true); }
I'm supposed to update the "10000" above to the actual event ID, but that is the event ID for my event in this case, based on what I see when I hover over "edit."
The problem is, I never get the email. I know the workflow is set up correctly, as I put another post function on the same transition to send an email, using the built in functionality of the Script Runner plugin. The reason this doesn't work for me is that I don't know how to set up a new velocity template to format the email the way I want. Right now the email just says "test."
Any help anyone can provide would be great. Let me know what other info you need. Thanks.
Hi Justin...
If you're just trying to raise an event when an Emergency issue is created, why don't you just use the "fire event when..." script which you can either use as a "script listener", or a workflow post-function. If you use that you just select the event and you condition would be: issue.getPriorityObject().getName().equals(
"Emergency"
)
I don't know why your script is not working though - I would add some log messages, and check your log file for errors.
BTW I am going away for a week with no access to email... hope my suggestion works because I won't be on this forum for a while.
I'm starting to think the plugin isn't working at all in the environment I'm using. This is a new env, and I can't get any of the functions of the plugin to work (e.g. setting the current user as a watcher if they're also the requestor). I'll keep looking into it. Thanks for your help (your suggestion makes sense, if I can work out the larger issue I'll try it out) and enjoy your trip.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
As always, first thing to do is check the logs and look for errors.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
are these the right logs to be looking at: Atlassian --> JIRA --> Logs --> access_log.2012-04-06
or should I be looking somewhere else? I don't see any errors in this log file.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
atlassian-jira.log...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
There was indeed an error thrown.
2012-04-09 11:33:54,403 http-80-8 ERROR justinc 693x18160x1 qsav9k 10.1.2.76 /secure/QuickCreateIssue.jspa [onresolve.jira.groovy.GroovyFunctionPlugin] Error executing post-function
this is followed by a bunch of lines like this:
java.lang.NullPointerException at com.atlassian.jira.issue.watchers.DefaultWatcherManager.startWatching(DefaultWatcherManager.java:44) at com.atlassian.jira.issue.watchers.WatcherManager$startWatching.call(Unknown Source)
of which there are too many to paste into here. Is there something in particular I should look for?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
OK, this issue seems to be related to the post function "assign current user as watcher" with the condition "currentUser == issue.reporter" and NOT an issue with the post function "fire an event when condition is true" with condition "issue.priority?.name == 'Emergency'"
I previously had both post functions in my workflow, but when I remove the first one and just leave the "fire event" post function, no error appears in the log, but I don't get an email either. Is there some other way to verify that the event is firing correctly so that I can pinpoint the point of failure?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Let's deal with one thing at a time. So the fire event thing first... set the log level to DEBUG as per https://studio.plugins.atlassian.com/wiki/display/GRV/Script+Runner#ScriptRunner-Logging, then in your logs you will see "Raising event...", if the condition matched. Have you configured it as a listener or a post-function?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
i've set this up as a post function. I added the following to the log4j.properties file:
log4j.category.com.onresolve.jira.groovy = DEBUG, console, filelog log4j.additivity.com.onresolve.jira.groovy = false
These were just added towards the top of the file. However, when I create an issue with priority "emergency", I don't see anything in the atlassian-jira.log file.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
just to be clear, here are my post functions:
Script workflow function : Fires an event that can be picked up by a notification scheme, in order to send mail only under certain conditions, eg Priority is Blocker — THEN The Creator of the issue will be set to %%CURRENT_USER%%. — THEN Creates the issue originally. — THEN Re-index an issue to keep indexes in sync with the database. — THEN Fire a Issue Created event that can be processed by the listeners.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Can you try the "condition tester" admin script, using the condition you have in the post script, and the issue that you created that should have fired the condition? Have you checked basic stuff like ensure the workflow draft is published, and that the issue has workflow you expect etc?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
on the "events" page of the admin section, my "Emergency Issue Created" event does NOT show as being tied to any workflows, but I'm assuming this is because I'm not using native JIRA functionality to fire that event, but rather this script. Just wanted to call that out in case I'm wrong.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
OK, using the condition tester, i get "The result evaluated to true" so it seems like the script recognizes that the issue is an emergency (or at least that's how I understand this result). If I'm not mistaken, the remaining points of failure are
1) the event is not getting fired
2) the event is not being recognized by the listener
3) the notification scheme is not set up correctly
does that sound right to you? and to your point about basic stuff, yes, workflow is active/published, the issue uses that workflow, etc.
I added an additional script to the transition as a check that everything was tied up correctly. This is the "send email based on a condition" script, and it works just fine, using the same condition as the "fire an event" script.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
> does that sound right to you?
Yeah, all sounds fine. 3) seems most likely. Is the notification scheme associated with the project? Sorry, I am fishing at last resorts here. If you have done this in a test database you could send it to me and I'd take a look.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'd be happy to send you a backup of our env. What's the best way to do that? I can be reached at ----- (in case you don't want to post your email address on here).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
In case anyone runs into the same issue - the problem turned out to be my "test case". I had my notification set up to send to my personal gmail account, so that I wouldn't confuse the "emergency" notification with the standard "issue created" notification. Apparently my mail server had an issue with sending to gmail accounts. When I switched the notification to go to a different user, it all worked perfectly.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
i've a similar problem.
I've create a send email listener on issue creation. that listener was sending to watchers a different email then the standard notification email
Issue are created by mail
All worked fine for some test. After some test a problem turn up.
When the listener trigger, seems that field are not valuated, the listerner doens't send any email. I've added another listener, based on a custom field that contain a direct email
That listener was originally used on issue comment event, not on creation. after adding it the on creation event, when it trigger i recieve an error of "cannot invoke method split" . That errors it's when u try to use a field with a blank value.
The script runner seems to trigger those "on create event" before the creation, and not after that. is it possible?
2012-06-14 01:43:50,578 QuartzWorker-0 DEBUG ServiceRunner HDtroble demo [jira.groovy.listener.ScriptRunnerUberListener] Fire class: com.onresolve.jira.groovy.canned.workflow.postfunctions.SendCustomEmail 2012-06-14 01:43:50,581 QuartzWorker-0 DEBUG ServiceRunner HDtroble demo [canned.workflow.postfunctions.SendCustomEmail] emailFormat: TEXT 2012-06-14 01:43:50,622 QuartzWorker-0 DEBUG ServiceRunner HDtroble demo [canned.workflow.postfunctions.SendCustomEmail] toConfig: "watchers" 2012-06-14 01:43:50,622 QuartzWorker-0 DEBUG ServiceRunner HDtroble demo [canned.workflow.postfunctions.SendCustomEmail] field f: "watchers" 2012-06-14 01:43:50,624 QuartzWorker-0 DEBUG ServiceRunner HDtroble demo [jira.groovy.listener.ScriptRunnerUberListener] Fire class: com.onresolve.jira.groovy.canned.workflow.postfunctions.SendCustomEmail 2012-06-14 01:43:50,626 QuartzWorker-0 DEBUG ServiceRunner HDtroble demo [canned.workflow.postfunctions.SendCustomEmail] emailFormat: TEXT 2012-06-14 01:43:50,660 QuartzWorker-0 DEBUG ServiceRunner HDtroble demo [canned.workflow.postfunctions.SendCustomEmail] toConfig: "customfield_10801" 2012-06-14 01:43:50,660 QuartzWorker-0 DEBUG ServiceRunner HDtroble demo [canned.workflow.postfunctions.SendCustomEmail] field f: "customfield_10801" 2012-06-14 01:43:50,704 QuartzWorker-0 ERROR ServiceRunner HDtroble demo [atlassian.event.internal.EventPublisherImpl] There was an exception thrown trying to dispatch event 'com.atlassian.jira.event.issue.IssueEvent@7bd835b[issue=HDDEMO-128,comment=<null>,worklog=<null>,changelog=<null>,eventTypeId=1,sendMail=true,params={eventsource=workflow, baseurl=https://.........},subtasksUpdated=false]' from the invoker 'com.atlassian.event.internal.SingleParameterMethodListenerInvoker@1b6b43ac'. java.lang.RuntimeException: Cannot invoke method split() on null object
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry, posted the script without changing the priority name. The priority is named "emergency" and I did change that in the script when I ran it.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I forgot to mention that I'm not sure if I put the script in the right place, or saved it with the right extension. I saved the scrpit above into a text file, and then changed the extension to .groovy. I put the file in the following place: Atlassian --> JIRA --> atlassian-jira --> scripts
where "scripts" is a folder that I added.
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.