Missed Team ’24? Catch up on announcements here.

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

Where to start looking when learning Groovy for JIRA?

Marcel_R__Ackermann February 15, 2012

Hi.

As far as I can tell, plugins like the Behaviours Plugin and the Script Runner use Groovy scripts to bring significantly more value to the workflows in JIRA. However, I am absolutely new to Groovy and, at the moment, I mainly use a trial-and-error approach to get my few scripts up and running (and I am not happy with that).

Can someone please direct me to some documentation or tutorial which helps learning the syntax/API/etc. that is needed when scripting for JIRA? Of course, any further helpful comments are also appreciated.

Many thanks in advance.

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

22 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.
February 15, 2012

Hi Marcel,

I think there's something to be said for the trial-and-error approach, to me it's more interesting and appropriate than book-learning. But you can only get so far like that, so yes, a combination is useful.

There are two aspects to the task here. 1) Learning enough groovy to be dangerous, and 2) Learning the jira API.

Learning enough groovy is the easier part, particularly if you have some familiarity with java, or even perl/python etc. There are quite a few good groovy tutorials, but do the examples in the groovy shell as you go, and change them etc. Even if you're not writing fantastically idiomatic groovy code, I think it's OK to learn "just enough", then over time you can keep coming back and learn say groovy-sql, xml builders and parsers, MOP, and so on.

OK so the hard part is learning what you need from the jira api, which is equally hard whatever language you're using. Get hold of Intellij IDEA... afaik the free edition is fine for this purpose. I wrote up how to set this up with jira a while ago, but I think it's still mostly valid. To me anyway, having intellisense and ctrl-q to view the javadoc is invaluable.

Download the jira source and open the pom file in IDEA. Then if you need to know how to do something, you can normally find it in the source. Start with the url name, eg ConfigureAppLinks, find that string in actions.xml, then open the class. Oh, and learn a few of the keyboard shortcuts in IDEA.

I have a groovy file in my project called Scratch,groovy, probably several times a day I'm hacking in that then running it in the script runner admin panel. Once I know how to do something, eg add a new applink or writing a groovy condition of some kind, then I will take that code and put it in the plugin I'm working on.

And finally, this is true of all languages, but imho, once you've got the basics from a book, pick a task and write it in the language. It should be easy to think of a task. For instance, years ago, I could see the pain my support team were having in setting up a project the same as an existing one, so I wrote the copy project plugin (now incorporated in script runner). I'm not at all proud of that code, but the point is it forced me to learn large parts of the API, eg around custom fields, schemes, role and user management and so on. Even though that was about 5 years ago, I still refer back to that code from time to time to see how to do something.

And also, feel free to ask questions on this forum. Most of the problems that people post on the script runner plugin pages are actually problems doing something with the API and not with groovy, so the questions are totally valid for AAC.

Good luck!

Marcel_R__Ackermann February 19, 2012

Thank you for such a thorough answer! I am sorry that I cannot upvote twice.

I see what you mean, yet I really like to work at least with some reference material to look up methods and signatures. (Well, I never seem remember method names correctly.) I know of the JIRA 4.4 API documentation and this is the kind of reference material I find it very useful. However, when working with, say, the Behaviours Plugin's Script Editor there is only a short summary of FormField methods. This is quite helpful, but I am wondering whether these are the only methods that are useful in this context. Also, what are the expected return types of the methods? E.g., I really had some trouble figuring out the return value of an unset Select List, and how to set it to another option. (I found out by trial and error, but it did cost me quite some time.)

Do you know of any resource material on that matter? Thanks again!

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.
February 19, 2012

Yeah, no-one can remember the method names, or the case etc, so that's why I think setting up an IDE is essential. The online API docs is fine but if you set up your IDE correctly that will be at your fingertips anyway.

> However, when working with, say, the Behaviours Plugin's Script Editor there is only a short summary of FormField methods

Ah well, now if you're talking about my plugins, then yes, fair point. I put some docs inline but it's not a substitute for proper javadoc which I will get round to updating and publishing... JBHV-124.

> Do you know of any resource material on that matter? Thanks again!

right now, the source code is the only authoritative doc...

Marcel_R__Ackermann February 19, 2012

Ah, I see. I kind of assumed that the scripting API was more universal than and not just for your plugin. Moreso, thanks for your efforts.

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.
February 19, 2012

Well, to clarify, for the script runner there is no "plugin api", it's just the jira api or whatever other app you are using. The behaviours plugin has a small api of its own concerned with serialising field states from the server to the client and back again, but 95% of your code would be using the jira api.

TAGS
AUG Leaders

Atlassian Community Events