Groovyrunner - Executing external script from Additional Issue Actions

Marc Batchelor January 20, 2014

I'd like to execute an external (on the file system) script from Additional Issue Actions instead of having the code hard-coded in the transition. The use case is a couple of transitions we use in-house that clone the current issue into a "backport" kind-of project. So - we have two x->x transitions (Open->Open, etc) that execute the "Clone to Another Project" script that then executes a wodge of script to set various field values and such (nulling out things that are not applicable, setting the case assignee, etc).

Right now, the same script is copied into several transitions ( Open->Open, In Progress->In Progress, etc) that clone an existing JIRA case into a companion case (and set a bunch of other settings in the case).

What I'd like to know is this - how (if possible), from the "Additional issue actions" code block, execute the code in a file on the server (instead of copy/paste the code into multiple transitions).

1 answer

0 votes
Henning Tietgens
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.
January 20, 2014

You could create a class with static methods within a groovy file, put this file in the corresponding path, import the class in additional issue actions and call methods from it.

A groovy file scripts.groovy with "package batchelor" at the beginning must be saved in atlassian-jira/WEB-INF/classes/batchelor/scripts.groovy and a defined class MyClass within this file can be imported with "import batchelor.MyClass".

Marc Batchelor January 21, 2014

Sorry, perhaps I wasn't as clear as I needed to be. Right now, we have several Post functions that call our own Groovy scripts in a folder on the server (away from the web-app, not in the WEB-INF/classes - just .groovy files). However, for one of our transitions, we're the Groovy-runner "Clones and issue and links" script (CloneIssue.groovy). In that transition, we have more Groovy code slammed into "Additional issue actions" to take care of custom field nulling, auto-creating a comment, etc. It's that code which I would like to move out of the transition and into an external file like all our other groovy scripts.

Ideally, the code that would be in "Additional issue actions" would have no actual logic in it - instead, it would be a few lines of groovy that would load the file and execute it's contents bringing along the state / context of what was being done. I played around with GroovyClassLoader and just executing the code, but it doesn't have the JIRA contextual information (like the issue object being created in the clone for example). So - there's got to be some special sauce that has to be used when invoking the script to know about all the bound variables in the environment. That's what I'm looking for - how to I invoke an external script from Additional issue actions with all the bound variables.

Henning Tietgens
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.
January 22, 2014

You could pass "binding" to the methods of the class I described above.

MyClass.doAdditional(binding)

Within the methods of the class you can access the bindings like this.

void doAdditional(Binding b) {
    def im = b.componentManager.issueManager
    //...
}

Suggest an answer

Log in or Sign up to answer