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

"Custom Script Listener" with Script Runner - ExampleListener not accepted

Test Name August 4, 2014

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"
    }
}
  1. I create subfolders: ...\Atlassian\JIRA\atlassian-jira\WEB-INF\classes\com\acme\listener\
  2. In folder listener, I create a file named ExampleListener.groovy and paste the code above into the file with Notepad++
  3. In JIRA, I go to Admin | Add-ons | SCRIPT RUNNER Script Listeners | Custom listener and fill out the form:
    Project Key: All projects
    Events: Issue Updated
    Name of groovy class: com.acme.listener.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:

  • Wrong imports
    I previously used
    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:

    Project Key: All projects
    Events: Issue Updated
    Name of groovy class: com.acme.listener.ExampleListener

    I encounter a NoClassDefFoundError
    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?

5 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
Alexey_Rjeutski__Polontech_
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.
August 20, 2014

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

JamieA
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.
August 20, 2014

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.

1 vote
JamieA
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.
August 20, 2014

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.

Alexey_Rjeutski__Polontech_
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.
August 20, 2014

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)

Leigh Grealis August 20, 2014

Ha - you've got enough to do already Jamie - keep up the good work

Leigh Grealis August 20, 2014

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.

Leigh Grealis August 20, 2014

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.

JamieA
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.
August 20, 2014

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.

Alexey_Rjeutski__Polontech_
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.
August 20, 2014

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).

JamieA
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.
August 21, 2014

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.

Alexey_Rjeutski__Polontech_
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.
August 21, 2014

Great great:) Waiting for the update)

Test Name August 21, 2014

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.

JamieA
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.
August 21, 2014

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.

0 votes
Jon Starbird
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.
November 19, 2014

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.

JamieA
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.
November 23, 2014

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) ?

Jon Starbird
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.
November 24, 2014

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.

Jon Starbird
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.
November 24, 2014

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,

JamieA
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.
November 24, 2014

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?

Jon Starbird
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.
November 24, 2014

I have the same problem on Firefox. A bit later I'll try it on another machine where I have IE11.

JamieA
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.
November 24, 2014

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...

Jon Starbird
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.
November 24, 2014

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?

JamieA
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.
November 24, 2014

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

Jon Starbird
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.
November 24, 2014

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&amp;projects=SM&amp;events=2&amp;clazz=com.listeners.myscript&amp;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&amp;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
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/&gt; &lt;title&gt;500 - Internal server error.&lt;/title&gt; &lt;style type="text/css"&gt; &lt;!-- 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;} --&gt; &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="header"&gt;&lt;h1&gt;Server Error&lt;/h1&gt;&lt;/div&gt; &lt;div id="content"&gt;  &lt;div class="content-container"&gt;&lt;fieldset&gt;   &lt;h2&gt;500 - Internal server error.&lt;/h2&gt;   &lt;h3&gt;There is a problem with the resource you are looking for, and it cannot be displayed.&lt;/h3&gt;  &lt;/fieldset&gt;&lt;/div&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt;

 

 

0 votes
Leigh Grealis August 20, 2014

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.

0 votes
Leigh Grealis August 20, 2014

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

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events