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

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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Tuesday in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

236 views 1 18
Join discussion

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