Groovy Script reassing issue

Marcin Beczynski May 12, 2016

Hi Guys,

I'm try to write some groovy script what should re-assign issue based on current assignee, but it wont work not even start. JIRA what I use is 6.3.15 and SR version is 3.1.3. I'm running script as a post function


Code of my Script. Thanks in advice for Help

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
 
MutableIssue issue = issue;
def userManager = ComponentAccessor.getUserManager()
    def Admin1 = userManager.getUserByName('Admin1')?.directoryUser
	def User1 = userManager.getUserByName('User1')?.directoryUser
    def Tester1 = userManager.getUserByName('Tester1')?.directoryUser
    def Admin2 = userManager.getUserByName('Admin2')?.directoryUser
    def User2 = userManager.getUserByName('User2')?.directoryUser
    def Tester2 = userManager.getUserByName('Tester2')?.directoryUser
	
//Team 1
	
    if(issue.assignee.equals(Admin1)) {
        issue.setAssignee(Tester1)}
		
	    if(issue.assignee.equals(User1)) {
        issue.setAssignee(Tester1))}
		
		    if(issue.assignee.equals(User1)) {
			issue.setAssignee(Tester1))}
//Team 2	
	if(issue.assignee.equals(Admin2)) {
        issue.setAssignee(Tester2)}
		
		if(issue.assignee.equals(User2)) {
        issue.setAssignee(Tester2))}
		
			if(issue.assignee.equals(User2)) {
			issue.setAssignee(Tester2))}

 

3 answers

1 accepted

0 votes
Answer accepted
adammarkham
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 12, 2016

Your script should look like the following. Note i've used == in the if statement and camel-cased variable names so its more readable.

This should set the assignee for you on the transition.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue

MutableIssue issue = issue;
def userManager = ComponentAccessor.getUserManager()
def admin1 = userManager.getUserByName('Admin1')?.directoryUser
def user1 = userManager.getUserByName('User1')?.directoryUser
def tester1 = userManager.getUserByName('Tester1')?.directoryUser
def admin2 = userManager.getUserByName('Admin2')?.directoryUser
def user2 = userManager.getUserByName('User2')?.directoryUser
def tester2 = userManager.getUserByName('Tester2')?.directoryUser

//Team 1
if (issue.assignee == admin1) {
    issue.setAssignee(tester1)
}

if (issue.assignee == user1) {
    issue.setAssignee(tester1)
}

if (issue.assignee == user1) {
    issue.setAssignee(tester1)
}
//Team 2
if (issue.assignee == admin2) {
    issue.setAssignee(tester2)
}

if (issue.assignee == user2) {
    issue.setAssignee(tester2)
}

if (issue.assignee == user2) {
    issue.setAssignee(tester2)
}
Marcin Beczynski May 12, 2016

Sitll error sad . I have it first as post function and in place of "Admin1" my username form JIRA right ?

adammarkham
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 12, 2016

Do you see any error messages? Anything in the logs to indicate what the problem is?

Marcin Beczynski May 12, 2016

2016-05-12 13:28:20,017 http-bio-8443-exec-7 ERROR mbeczynski 808x33394x1 1nspkgu 195.205.243.130 /secure/WorkflowUIDispatcher.jspa [scriptrunner.jira.workflow.ScriptWorkflowFunction] *************************************************************************************
2016-05-12 13:28:20,018 http-bio-8443-exec-7 ERROR mbeczynski 808x33394x1 1nspkgu 195.205.243.130 /secure/WorkflowUIDispatcher.jspa [scriptrunner.jira.workflow.ScriptWorkflowFunction] Script function failed on issue: SGSP-53, actionId: 711, file: /var/atlassian/application-data/jira-production/scripts/InProgressToCodeReview.groovy


Only This nothing what could help me 

adammarkham
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 12, 2016

Can you try removing all of your script and just having the following line in it and seeing if that runs correctly? If that works then its likely to be an error in the script.

log.warn("Running script")
Marcin Beczynski May 12, 2016

Nothing at console, so it can be something wrong with JIRA or Script Runner plugin ??

adammarkham
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 12, 2016

Do you still see same error message in the logs? 

016-05-12 13:28:20,017 http-bio-8443-exec-7 ERROR mbeczynski 808x33394x1 1nspkgu 195.205.243.130 /secure/WorkflowUIDispatcher.jspa [scriptrunner.jira.workflow.ScriptWorkflowFunction] *************************************************************************************
2016-05-12 13:28:20,018 http-bio-8443-exec-7 ERROR mbeczynski 808x33394x1 1nspkgu 195.205.243.130 /secure/WorkflowUIDispatcher.jspa [scriptrunner.jira.workflow.ScriptWorkflowFunction] Script function failed on issue: SGSP-53, actionId: 711, file: /var/atlassian/application-data/jira-production/scripts/InProgressToCodeReview.groovy

Marcin Beczynski May 12, 2016

nope it just show nothing at all, I made perform reindexing now maybe that will resolve this issue 

adammarkham
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 12, 2016

It seems like the post-function isn't firing. Do you have permission to do the transition?

Marcin Beczynski May 12, 2016

yep I had all permission it start work after re index instance + clear cache and groovy internal cache and re index issue at project . Thanks you for your time and help if you will be at Poland let me know I own you a beer 

0 votes
Marcin Beczynski May 12, 2016

. I'm running script as a post function 

0 votes
adammarkham
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 12, 2016

Your script won't compile. You have extra ')' near the if statements. Are you adding this script as part of a post-function or listener? More details would be good so I can give you a more useful answer.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events