Hi everybody, since I am struggling to create a "Custom Script Listener" with Script Runner, I hope that someone can help.
JIRA version: 6.3.1
Script Runner version: 3.0.3
Here's my code, basically copied from https://jamieechlin.atlassian.net/wiki/display/GRV/Listeners:
package com.acme.listener import com.atlassian.jira.event.issue.AbstractIssueEventListener import com.atlassian.jira.event.issue.IssueEvent import org.apache.log4j.Logger class ExampleListener extends AbstractIssueEventListener { Logger log = Logger.getLogger("log4jLogger") @Override void workflowEvent(IssueEvent event) { log.debug "Event fired by ExampleListener" } }
-> Validations says: Problem loading class: com.acme.listener.ExampleListener
Allthough documentation says at https://jamieechlin.atlassian.net/wiki/display/GRV/Listenersfor advanced users step 2: Copy the .groovy file to the correct place under the classes directory (depending on its package) nothing happens in my case.
I've been thinking of the following error sources:
Category log = Category.getInstance(ExampleListener.class)
but since I read about some probs with mistakenly used Loggers https://answers.atlassian.com/questions/265111/scriptrunner-getting-noclassdeffounderror-for-groovyobject I tried to use it in the most basic way.
JIRA testversion
I've installed a testversion of JIRA with does not run as a service. As a benifit of that, I can test groovy-scripts (POST-functions work like a charm with IDEA remote debugging) without touching the production environment. Anyway, maybe the Tomcat does not have adminrights. I tried to fix that in starting the commandline as admin and from there I start the Tomcat with
set JPDA_TRANSPORT=dt_socket set JPDA_ADDRESS=8000 bin\catalina.bat jpda start
Groovy compiler
I also tried to compile the ExampleListener.groovy (with IDEA and with cmd groovyc) and paste the .class file into ...\Atlassian\JIRA\atlassian-jira\WEB-INF\classes\com\acme\listener\
When I then again fill out the form in JIRA Admin | Add-ons | SCRIPT RUNNER Script Listeners | Custom listener with:
java.lang.NoClassDefFoundError: groovy/lang/GroovyObject at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:800) ... at java.lang.ClassLoader.loadClass(ClassLoader.java:412) at groovy.lang.GroovyClassLoader.loadClass(GroovyClassLoader.java:655)
My IDEA-groovy version is 2.3.2, in ...\Atlassian\Application Data\JIRA\plugins\... theres a groovy-all-2.3.1.jar...
I'm out of ideas, anyone can help? Most of all, am I right in using the uncompiled .groovy file?
Community moderators have prevented the ability to post new answers.
You've put the wrong place to store listeners. please try something like g:\jiradata\6.3\scripts\com\polontech\listener\ExampleListener.groovy
Place inside your data folder under scripts directory with all that path
This is absolutely correct for Script Runner 3 onwards. When upgrading from 2.x see the (todo) documentation for upgrading with custom listeners, it will be linked from here https://jamieechlin.atlassian.net/wiki/display/GRV/Upgrading+to+3.0.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
As Alexey says, this has changed in 3+, it needs to go under a script root.
It was important to me that any code lived outside the installation dir, and moving to a script root brings other advantages.
I need to document in the upgrade guide what changes you need to make, which in the case of custom listeners, is mainly to move them to a script root. Sorry I haven't done this yet.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That is really cool that scripts don't need to be migrated for each upgrade) You've made a great job with that sript runner - that is my favorite tool)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ha - you've got enough to do already Jamie - keep up the good work
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thought I'd tried that - I probably mismatched the classname or path or something when I was trying different options - will give it a go. Wasn't happy with my solution of regressing to groovy-2.x so thanks for quick answers guys :)
Completely agree it's great that these can sit under the jira data folder - good rework Jamie. This plugin has got me out of jail with subtle requirements so many times on implementations when there's not enough time to write a full plugin.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Validated your response works with 3.0.4 Alexey - I can't mark you as correct response as didn't raise the question.
Summary for all others:
Class ChangeListener is saved as ChangeListener.groovy under <JIRA_HOME>/scripts/com/custom
Package is called com.custom
Added the following parameter to jvm startup:
-Dplugin.script.roots=D:\atlassian\data\jira-home\scripts
Everything works a dream.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Leigh - thanks a lot for that.
All that you wrote there is correct, but the last bit is not necessary. You can add additional script roots using that property, but <home>/scripts is always a valid script root by default, and the plugin should create that directory if it wasn't present.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It would be great to omit usage of that directory at all - it would be great if it would be possible to put scripts directly through web interface (i.e. save them automatically to that directory or use active objects).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You should be able to store your code in the database everywhere now, eg workflow functions, listeners, fields etc. Only place where this is not possible is with jql functions.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Great great:) Waiting for the update)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks all, I didn't upgrade from 2.x but started from scratch 3.x. So I didn't read the upgrade info, in addition to that I must have read an old documentation.
I've marked Alexeys answer as correct response.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm going to move the documentation out of confluence, as I need different docs for different versions. The doc you read must not be up to date for 3.0... will fix that.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm hitting this issue but cannot get it resolved. I have the folder set as <jirahome>/scripts/com/listeners/ with my file there and I'm just using the Example code for now. When I configure the Customer Listener and try to add JIRA just spins, it never gets added and nothing is ever added to the logs. It just does nothing.
I end up having to kill it off.
In the config screen I'm entering the path to the script as:
com.listeners.Example
That is the correct way?
JIRA 6.3.7 and plugin 3.0.6.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Can you hit F12 and check for any javascript errors. If you put the class in that folder the package needs to be "com.listeners". Also, can you confirm the sample code you are talking about is this: https://jamieechlin.atlassian.net/wiki/display/GRV/Listeners#Listeners-CustomGroovyListeners(foradvancedusers) ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Jamie, sorry I double posted. I forgot I had posted here on this thread. I later created a new issue: https://answers.atlassian.com/questions/10417552/script-runner---custom-script-listener-cannot-load where you asked me to post my code which I did. Still going to try your suggestion of F12, didn't realize it was JavaScript in use at that time.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Tried using F12, also added com to the package line, got the following error: post to: /jira/rest/scriptrunner-jira/latest/listeners/com.onresolve.scriptrunner.canned.jira.workflow.listeners.CustomListener SCRIPT1014: Invalid character batch.js, line 22 character 226 This is on IE10,
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am not that thorough on IE testing as I never use it, but I forced myself to test on IE11. Can you try another browser just in case it is browser-specific?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have the same problem on Firefox. A bit later I'll try it on another machine where I have IE11.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
it's probably not a browser issue then. A decent browser will let you get the javascript stack trace, if you can post that please...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I hit the same issue on IE11. I went back to Firefox to try Firebug info on it and I did get a bit more info. It seems to be failing at this spot in Batch.js: function Sa(a, b, c) { var e = b + 'defer', f = b + 'queue', g = b + 'mark', i = d._data(a, e); i && (('queue' === c || !d._data(a, f)) && ('mark' === c || !d._data(a, g))) && setTimeout(function () { !d._data(a, f) && !d._data(a, g) && (d.removeData(a, e, !0), i.fire()) }, 0) } It breaks specifically at the line of : f = b + 'queue', Firebug says it's a Syntax Error from JSON.parse, unexpected character at line 1 column 1 of the JSON data. Could it be our Jira verison, 6.3.7, with the latest plugin version that is the issue?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I don't think so. We need to see what is in the data. Firefox or chrome will let you see the contents of the request/response. Alternatively you can capture a transcript using Fiddler and let me have that, that may be easiest. http://www.telerik.com/fiddler
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Here are the request and response. It looks like it's getting a 500 error but I'm not sure what it's getting the 500 error on, the script or a file within Scriptrunner.
I changed the script to match exactly to your Example from the doc page for Script Runner, the on you sent me a link to before, just to eliminate any other possible code issues.
Request:
POST /jira/rest/scriptrunner-jira/latest/listeners/com.onresolve.scriptrunner.canned.jira.workflow.listeners.CustomListener HTTP/1.1 Accept: application/json, text/javascript, */*; q=0.01 Content-Type: application/x-www-form-urlencoded; charset=UTF-8 X-Atlassian-token: nocheck X-Requested-With: XMLHttpRequest Referer: http://jserver/jira/plugins/servlet/scriptrunner/builtin?section=script_listeners#com.onresolve.scriptrunner.canned.jira.workflow.listeners.CustomListener Accept-Language: en-US Accept-Encoding: gzip, deflate User-Agent: Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0) Connection: Keep-Alive Content-Length: 422 DNT: 1 Host: jserver Pragma: no-cache Cookie: JSESSIONID=404447C527B36C208FB7088223D0E6E5; G2G.crmplugin.cookie=g2g-crm-saved%3Dtrue; seraph.rememberme.cookie=14635%3A2c6bda910a314cb173a71e1dfd47530c778e134f; atlassian.xsrf.token=BHQY-8L7D-OBQ7-K2JR|28135c03b7974143442d8e4c760f011805f34196|lin; AJS.conglomerate.cookie="|upm.tab=licenses|workflow-mode=diagram|upm.pageReloadPerformed=true|sd.featuretour.display.help=false"; doc-sidebar=273px; __utma=1.559295608.1375309148.1380839946.1380910019.33; gh.i=%7B%7D; upm.atl.id=tuser%7C85b0fb9bcd79df6d408ddce3f49f1faba3ceec719008012c884df1d7346c3c07; mywork.tab.tasks=false FIELD_LISTENER_NOTES=Test&projects=SM&events=2&clazz=com.listeners.myscript&scriptParams=%7B%22FIELD_LISTENER_NOTES%22%3A%22Test%22%2C%22projects%22%3A%22SM%22%2C%22events%22%3A%222%22%2C%22clazz%22%3A%22com.listeners.myscript%22%2C%22canned-script%22%3A%22com.onresolve.scriptrunner.canned.jira.workflow.listeners.CustomListener%22%7D&canned-script=com.onresolve.scriptrunner.canned.jira.workflow.listeners.CustomListener
Response:
HTTP/1.1 500 Internal Server Error Cache-Control: no-cache, no-store, no-transform Content-Type: text/html Vary: User-Agent Server: Microsoft-IIS/8.0 X-AREQUESTID: 1016x21686x1 X-ASESSIONID: nri2r1 X-ASEN: SEN-2532900 X-Seraph-LoginReason: OK X-AUSERNAME: tuser X-Content-Type-Options: nosniff Date: Tue, 25 Nov 2014 00:56:33 GMT Content-Length: 1208 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/> <title>500 - Internal server error.</title> <style type="text/css"> <!-- body{margin:0;font-size:.7em;font-family:Verdana, Arial, Helvetica, sans-serif;background:#EEEEEE;} fieldset{padding:0 15px 10px 15px;} h1{font-size:2.4em;margin:0;color:#FFF;} h2{font-size:1.7em;margin:0;color:#CC0000;} h3{font-size:1.2em;margin:10px 0 0 0;color:#000000;} #header{width:96%;margin:0 0 0 0;padding:6px 2% 6px 2%;font-family:"trebuchet MS", Verdana, sans-serif;color:#FFF; background-color:#555555;} #content{margin:0 0 0 2%;position:relative;} .content-container{background:#FFF;width:96%;margin-top:8px;padding:10px;position:relative;} --> </style> </head> <body> <div id="header"><h1>Server Error</h1></div> <div id="content"> <div class="content-container"><fieldset> <h2>500 - Internal server error.</h2> <h3>There is a problem with the resource you are looking for, and it cannot be displayed.</h3> </fieldset></div> </div> </body> </html>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
NOTE: I've loaded scriptrunner 2.1.17 into Jira 6.3.1 (with a little tidying up), it's now recognising the listener class. Obviously got some testing to do on this but don't see any log errors (well, serious ones anyway I think). Had to reconfigure post function scripts stuff but that's not a problem and they look ok at first glance also.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Andreas,
I'm actually facing exactly the same problem. I've tried 3.0.1 and 3.0.4 versions of the groovy plugin with Jira 6.3.1 and whatever I do (same steps as you) keep getting the "problem loading class" problem.
Don't support you worked this one out? I've never had to compile the class before - that's the main point of using scriptrunner over a fullblown plugin.
To check I wasn't going mad I've gone back to Jira 6.1.7 on another machine and performed exactly the same configuration except this uses the 2.1.16 version of ScriptRunner plugin and have no such problems - the class seems to load fine...
Jamie - I know we should raise a support ticket for this - and I will do in a minute - but is this something that's known?
I'm thinking about trying to regress and use the 2.1.16 ScriptRunner plugin in Jira 6.3.1 to see if that works before I raise a ticket.
Cheers,
Leigh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.