Groovyrunner - Executing external script from Additional Issue Actions

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 Community Champion Jan 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".

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 Community Champion Jan 22, 2014

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


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
Community showcase
Published Nov 27, 2018 in Portfolio for Jira

Introducing a new planning experience in Portfolio for Jira (Server/DC)

In the past, Portfolio for Jira required a high degree of detail–foresight that was unrealistic for many businesses to   have–in   order to produce a reliable long-term roadmap. We're tur...

2,516 views 15 20
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you