Hello,
I am looking for a way to use a groovy script to assign watchers of a ticket on creation based on the priority assigned.
Does anyone know if this is possible or has anyone successfully done this before?
Thanks!!
Made that change which resulted in another error... thanks for your help, maybe we can get this working with a little more tweaking...
current error:
Caused by: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script3.groovy: 36: unable to resolve class MutableIssue
@ line 36, column 14.
MutableIssue mutableIssue = (MutableIssue) issue;
^
Script3.groovy: 36: unable to resolve class MutableIssue
@ line 36, column 29.
MutableIssue mutableIssue = (MutableIssue) issue;
^
2 errors
at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:302)
at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:858)
at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:548)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:497)
at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:306)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:287)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:267)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:214)
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.getScriptClass(GroovyScriptEngineImpl.java:337)
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:109)
... 147 more
Where are you copying/adapting this from? You are missing the imports.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Script I tried below:
package com.onresolve.jira.groovy.canned.workflow.postfunctions
import com.atlassian.jira.ComponentManager
def componentManager = ComponentManager.getInstance()
def watcherManager = componentManager.getWatcherManager()
def userManager = componentManager.getUserUtil()
//******************Declaring watchUsers function**********************************
def watchUsers = {usernames ->
usernames.each {
def user = userManager.getUser(it)
watcherManager.startWatching(user, issue.getGenericValue())
}
}
//******************End Declaration of watchUsers function*************************
////******************Defining user groups*******************************
def SHOWSTOPPER_users = ["testuser1"];
def HIGH_users = ["testuser2"];
def MEDIUM_users = ["testuser3"];
def LOW_users = ["testuser4"];
def VERYLOW_users = ["testuser5"];
////******************End user group definitions*************************
////******************Defining user test groups*******************************
def SHOWSTOPPER_test = ["testuser1"];
def HIGH_test = ["testuser2"];
def MEDIUM_test = ["testuser3"];
def LOW_test = ["testuser4"];
def VERYLOW_test = ["testuser4"];
////******************End user test group definitions*************************
MutableIssue mutableIssue = (MutableIssue) issue;
def priority = mutableIssue.getPriority().getString("name");
if(priority.equals("5-Showstopper")){
//Assign to watchers who need for showstopper
//watchUsers(SHOWSTOPPER_users);
watchUsers(SHOWSTOPPER_test);
}
else if(priority.equals("4-High")){
//Assign to watchers who need for high
//watchUsers(HIGH_users);
watchUsers(HIGH_test);
}
else if(priority.equals("3-Medium")){
//Assign to watchers who need for medium
//watchUsers(MEDIUM_users);
watchUsers(MEDIUM_test);
}
else if(priority.equals("2-Low")) {
//Assign to watchers who need for low
//watchUsers(LOW_users);
watchUsers(LOW_test);
}
else if(priority.equals("1-Very Low") ) {
//Assign to watchers who need for very low
//watchUsers(VERYLOW_users);
watchUsers(VERYLOW_test);
}
else //No priority is assigned.
//Assign no watchers one.
Error I found in the JIRA log after running:
Caused by: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script2.groovy: 65: unexpected token: @ line 65, column 28.
//Assign no watchers one.
^
1 error
at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:302)
at org.codehaus.groovy.control.ErrorCollector.addFatalError(ErrorCollector.java:149)
at org.codehaus.groovy.control.ErrorCollector.addError(ErrorCollector.java:119)
at org.codehaus.groovy.control.ErrorCollector.addError(ErrorCollector.java:131)
at org.codehaus.groovy.control.SourceUnit.addError(SourceUnit.java:359)
at org.codehaus.groovy.antlr.AntlrParserPlugin.transformCSTIntoAST(AntlrParserPlugin.java:141)
at org.codehaus.groovy.antlr.AntlrParserPlugin.parseCST(AntlrParserPlugin.java:107)
at org.codehaus.groovy.control.SourceUnit.parse(SourceUnit.java:236)
at org.codehaus.groovy.control.CompilationUnit$1.call(CompilationUnit.java:160)
at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:843)
at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:548)
at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:524)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:501)
at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:306)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:287)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:267)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:214)
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.getScriptClass(GroovyScriptEngineImpl.java:337)
at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:109)
... 147 more
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Looks like your script ends with the keyword "else" ?
That's not valid.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Just remove the final "else"... then it should be ok.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.