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

Jelly Script >> Add Watcher To Parent Issues

jhreeves2001 April 29, 2012

Summary: Within JIRA Administration -- Advanced -- Services, I'd like to "Add Service" to "Run Jelly script" that would add watchers to many Parent Issues. I have no experience with Jelly scripting.

Using Jelly Script, can someone create the code framework to accomplish the following:

  • Within Project X
    • For each and every Issue that the following 3 criteria equate to True
      1. NOT a subtask, and
      2. Status <> "Closed", and
      3. Contains a Subtask with Summary field == "HelpTylerHesNotSmart"
    • TRUE >>> Add each user - who is of the Role == "KingOfTheHill" - as a Watcher to the Parent Issue mentioned above.
    • FALSE >> Remove any Watcher from the Parent Issue mentioned above

My goal is to "Add Service" and run this code each day.

Thank you for your consideration and guidance.

7 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

2 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 30, 2012

OK, here it is... I've not really tested, I'll leave that to you.

Before installing as a service, you can (must) test it in the script runner admin panel. You can put the file on the server, then in the admin panel point to that, and Run.

After that it's easier to install a service which will run every X minutes.

I've left some debug statements in there which you can remove if/when it works.

Code: https://gist.github.com/2561925

jhreeves2001 April 30, 2012

Jamie --- thanks so much for this; please give me a day to incorporate; your work is amazing. Take care, Tyler

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 30, 2012

No worries - I used a project key called JRA, you need to change that to project X or whatever. Give me a shout if you have any problems.

jhreeves2001 April 30, 2012

Thanks Jamie! Will do! SAF and Mancini were going at it, yesterday, ehh?

Dieter
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 30, 2012

Great Stuff! Thanks to Groovy the implementation almost reads like the specification :-)

jhreeves2001 April 30, 2012

Hi Jamie, thanks again for all of your help and guidance.

Through Script Runner, I've transferred your code (adjusting for projectKey and roleName specifics) to the Script Engine (Groovy type) and pressed Run. Here is the main error message:

  • javax.script.ScriptException. groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.issue.watchers.DefaultWatcherManager.StartWatching() is applicable for argument types: (com.opensymphone.user.User, org.ofbiz.core.entity.GenericValue) values [tylerp, [summary:BULCTHGIF, votes:0, ...]]

I received a few other error messages (Null Pointers), but believe I caused those by commenting out each (from the start and stop sections) log line (lines 39 and 46) and the start/stop watching commands (lines 40 and 47).

Thanks for your help, Tyler

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 30, 2012

I just tested it on 4.4.3 and it worked...

Dieter, I agree. Groovy cuts out all the boilerplate in java where you have to search through 10 interfaces and 5 abstract classes to get to the little bit of business logic.

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 30, 2012

Like I said, I didn't test it ;-)

What jira version is it?

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 30, 2012

> received a few other error messages (Null Pointers), but believe I caused those by commenting out each (from the start and stop sections) log line (lines 39 and 46) and the start/stop watching commands (lines 40 and 47).

Don't really understand that - could you paste your code up to gist.github.com. You can comment out the stop/start watching but don't comment out the .each{}

jhreeves2001 April 30, 2012

Hi Jamie, thanks again for leading me through this.

I think I did the gist posting correctly: https://gist.github.com/2569617

Update:

  • I no longer receive the "groovy.lang.MissingMethodException" error message. Sorry about this --- I inadvertently entered miscellaneous text into the code.
  • If I run the code shown in gist posting (2569617) as is, it appears to run correctly (I get a stream within the results section ---> [com.atlassian.jira.issue.DocumentIssueImpl@4b9f66d0, ...])
  • If I remove the comment tags, I now receive the following message: "javax.script.ScriptException: java.lang.NullPointerException" ---- I've made sure that there exist the correct projectKey and roleName and that there exists at least one parent issue containing a subtask with Summary field == YYYYYY.

EDIT ---> Sorry, I forgot to include JIRA version: v4.4.4

Thanks Jamie, Tyler

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 30, 2012

Can you post the first few lines of the NullPointerException?

> I've made sure that there exist the correct projectKey and roleName

Yes, minimal error checking so they need to exist.


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.
May 1, 2012

Heh... I don't care about any team that isn't Arsenal ;-)

Sorry, I will need the full stack trace. Can you post to gist. I'm wondering if you have a problem with your indexes - can you incorporate the changes from https://gist.github.com/2575893 .

jhreeves2001 May 1, 2012

Thanks Jamie, here are the first few lines:

>> javax.script.ScriptExcepton: javax.script.ScriptException: java.lang.NullPointerException

at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEnglineImpl.java:117)

at javax.script.AbstractScriptEngine.eval(AbstractScriptEngline.java:216)

at com.onresolve.jira.groovy.GroovyRunner.runFile(GroovyRunner.java:99)

at com.onresolve.jira.groovy.GroovyRunner.run(GroovyRunner.java:50)

at com.onresolve.jira.groovy.GroovyRunner.doExecute(GroovyRunner.java:220)

at webwork.action.ActionSupport.execute(ActionSupport.java:165)

at com.atlassian.jira.action.JiraActionSupport.execute(JiraActionSupport.java:76)

at webwork.interceptor.DefaultInterceptorChain.proceed(DefaultInterceptorChain.java:39)

at webwork.interceptor.NestedInterceptorChain.proceed(NestedInterceptorChain.java:31)

at webwork.interceptor.ChainedInterceptor.intercept(ChainedInterceptor.java:16)

at webwork.interceptor.DefaultInterceptorChain.proceed(DefaultInterceptorChain.java:35)

at webwork.intercetpor.GenericDispatcher.executeAction(GenericDispatcher.java:205)

Madrid could wrap up the domestic league today, no? Red Devils... destiny out of their control now -- that drubbing to City (@ Old Trafford) really killing the goal differential...

jhreeves2001 May 1, 2012

Gunners --- I see where you are now. :) Arsene Wenger is the man --- and RVP has a deadly left side.

Update ----- Jamie, I'm sorry, I just retested and noticed that I have a ton of watchers on the parent issue of a subtask with the YYYYYY summary. While I'm still receiving the Null Pointer Exception, your ORIGINAL CODE does complete the task set out by the specs. Please give me a moment to incorporate your updated code from gist 2575893.

Thanks Jamie, Tyler

jhreeves2001 May 1, 2012

Hi Jamie,

Sorry for my delay; two points / questions:

  1. Even with the NullPointerException --- your code still works. Can I just ignore? I see nothing in the log files.
  2. I can post the full stack trace, but it will take me a little while. After commenting out certain sections, I believe the issue.subTaskObjects.any statement is causing the exception.

Thanks, Tyler

0 votes
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 30, 2012

I'm listening to it in the background ;-)

0 votes
jhreeves2001 April 30, 2012

Hi Jamie -- I appreciate this (hope I'm not taking you away from the important Derby).

0 votes
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 30, 2012

Yes... it's actually quite a complex task (almost impossible in jelly)... I'll put something together but can't guarantee it will work right off the bat.

0 votes
jhreeves2001 April 30, 2012

Hi Jamie, can the code be set up to execute every X minutes?

0 votes
jhreeves2001 April 29, 2012

Hi Jamie --- I've installed the script runner plug-in >>> karma is yours!

0 votes
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 29, 2012

Would you be prepared to install the script runner plugin to do this via a service written in groovy? If so I'd give you the code, for a guaranteed karma influx.

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events