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

ScriptRunner's CLASSPATH, or how to use Groovy classes for validation

Michele Zamparelli April 14, 2014

Dear all,

I am using successfully the ScriptRunner with Groovy scripts for

postconditions etc.

Now I would like to make a library of functions in groovy and put it

into a class, so that is methods are called by different script as

post functions for different transitions.

I am knowledgeable enough of Java's package/import/classpath

philosophy, but I do not know how this translates in the JIRA

standalone/Script Runner set-up.

I have the following files:

TestGroovy.groovy

// start code snippet

package sed.jira;

 

import com.atlassian.jira.ComponentManager

 

import java.util.HashMap

import com.atlassian.jira.issue.CustomFieldManager

import com.atlassian.jira.issue.Issue

import com.atlassian.jira.issue.MutableIssue

import com.atlassian.jira.issue.comments.CommentManager

...

import com.atlassian.jira.event.type.EventDispatchOption

 

 

import sed.jira.JiraLibrary;

 

JiraLibrary jl = new JiraLibrary();

 

def Category log = Category.getInstance("com.onresolve.jira.groovy.PostFunction"

);

log.setLevel(org.apache.log4j.Level.DEBUG);

 

// end code snippet

 

and a simple: 

 

// start code snippet

package sed.jira;

 

class JiraLibrary { 

      String myMethod(String pippo) { 

          return pippo+ ":" + pippo;

      }     

}

 

// end code snippet

I would like TestGroovy.groovy to be called by the ScriptRunner

but it fails with:

unable to resolve class sed.jira.JiraLibrary @ line 24, column 1

I guess my question boils down to:

a) do I need somehow to compile (I do not have a groovy compiler on my

Jira box) the code and package it in a jarfile or similar?

b) what would I put the scripts or the compiled versions thereof?

What's ScriptRunner (or JIRA's ) CLASSPATH?

Thanks

Michele

2 answers

1 accepted

Suggest an answer

Log in or Sign up to answer
0 votes
Answer accepted
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.
April 15, 2014

Michele - there is information on this here: https://jamieechlin.atlassian.net/wiki/display/GRV/Upgrading+to+3.0(under "script roots" section) - but it's only pertinent to the new beta version.

You can download it from the same page if you have a recent enough jira instance.

For the current version you need to compile a jar really, although I would recommend trying the new version as using dependent classes and libraries will be much easier.

David_Turner June 19, 2014

Hi Jamie,

Running Jira 6.2.2 on Windows. Had a post-function and listener-enabled class in package com.onresolve.jira.groovy.canned.workflow.postfunctions.

Just upgraded Script Runner 2.2.x to to 3.0-b11 in order to get Behaviours function back, and now when I view ScriptRunner Listeners, I see an 'undefined' value and getting an error in atlassian-jira.log:

2014-06-20 15:28:47,401 ajp-apr-8009-exec-9 ERROR <user> 928x25038x2 6mf16d <ip> /rest/scriptrunner-jira/latest/listeners [scriptrunner.runner.rest.AbstractRestEndpoint] Could not get script name:
groovy.util.ResourceException: Malformed URL: bundle://177.0:0/, null
    at groovy.util.GroovyScriptEngine.getResourceConnection(GroovyScriptEngine.java:373)    at groovy.util.GroovyScriptEngine.loadScriptByName(GroovyScriptEngine.java:513)

Caused by: groovy.util.ResourceException: Malformed URL: file:/C:/Tools/Atlassian/JIRA-Data/scripts/, null

Naturally, this is referring to the newly created 'script-root' directory introduced in 3.0.

Attempting to resolve, I've just moved my old post-function script (with full path) into the new 'scripts' directory and added "-Dplugin.script.roots=C:\Tools\Atlassian\JIRA-Data\scripts" to Java Opts (but not changed classpaths yet).

But this hasn't helped. Same error.

Any ideas?

David_Turner June 19, 2014

Seems adding Dplugin.script.roots was unnecessary; now that default path is included twice (if Script Console is anything to go by).

Hmm, hope I'm not going bonkers but it looks like the scriptrunner utility groovies/classes etc have moved to a new package/path; if so this might need to be noted on the 3.0 pages!?

From 2.2: com.onresolve.jira.groovy.canned.*

Now 3.0: com.onresolve.scriptrunner.canned.jira.workflow.postfunctions
com.onresolve.scriptrunner.canned.jira.utils etc?

I'll need to adjust imports and try again.

EDIT: -- Yep, that's done it. Adjusted the packages and my class now appears in the Script Listeners list again. Bril. :)

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.
June 22, 2014

David - yes, some packages were moved, sorry about that but I didn't have much choice. I need to document that.

I will make it so that it doesn't add the path twice...

I'm not really sure why you got the malformed url exception though, looks ok.

0 votes
Paresh Gandhi
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.
April 14, 2014

try below exmple:

import com.atlassian.jira.event.issue.AbstractIssueEventListener

class JiraLibrary extends AbstractIssueEventListener {

@Override

void issueUpdated (IssueEvent event) {

}

}

TAGS
AUG Leaders

Atlassian Community Events