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

can't figure out how to debug my scriptrunner script

Esty Heller June 17, 2013

I'm trying to write a postfunction script to check the value of a custom field (Assigned Tester). If it's empty, I want to get the reporter of the issue, check if he is part of the Assigned Tester role, and if so, assign him to this custom field.

I'm getting stuck on this error java.lang.ClassCastException: com.atlassian.jira.user.BridgedDirectoryUser cannot be cast to com.atlassian.jira.user.ApplicationUser

I'm new at this, and I can't figure out how to debug... I tried system.out.println, but I don't know where I would see it? I trailed the output log atlassian-jira.log (that's where I see the error message), but I don't see anything that I'm trying to print out.

Here is the part of my code that is having trouble, I appreciate any tips.

ComponentManager componentManager = ComponentManager.getInstance()
CustomField assignedTester = componentManager.getCustomFieldManager().getCustomFieldObjectByName("Assigned Tester")


if (assignedTester.getValue(myIssue) == null){
	//check if the reporter can be a tester
	User myReporter = myIssue.getReporter()
	//User myOldTester = issue.getCustomFieldValue(assignedTester)
	ProjectRoleManager projectRoleManager = ComponentManager.getComponentInstanceOfType(ProjectRoleManager.class) as ProjectRoleManager
	ProjectRole testRole = projectRoleManager.getProjectRole("Assigned Testers")
	if (projectRoleManager.isUserInProjectRole(myReporter, testRole, issue.getProjectObject())){
		//the reporter can be a tester, so assign him
		IssueChangeHolder changeHolder = new DefaultIssueChangeHolder();
		assignedTester.updateValue(null, issue, new ModifiedValue(null, myReporter), changeHolder)
	}
}

6 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

11 votes
Answer accepted
Henning Tietgens
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.
June 17, 2013

To get debug messages you can use the object log (org.apache.log4j.Category). It's already binded to your script. So if you write

log.error "Debug message"

you will see this message in the atlassian-jira.log. You could implement different levels of debug messages. log.debug(), log.info(), log.warn() and log.error() and set the log level at the beginning of your script.

log.setLevel(org.apache.log4j.Level.DEBUG)

In this way you can develop with log level debug and after finishing raise the level to error to get only important messages in the log.

Henning

Esty Heller June 17, 2013

thanks, i can see the messages now

2 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.
June 17, 2013

Take a look at this page: https://developer.atlassian.com/display/JIRADEV/Renamable+Users+in+JIRA+6.0#RenamableUsersinJIRA6.0-ConvertingbetweentheUserobjectandtheApplicationUserobject

You will need to convert the user types, or get a new User object from the key of the applicationUser (or something).

Esty Heller June 17, 2013

jamie, thanks for the link. still working on this, and after many hours, not getting anywhere.

which user needs to be converted? the reporter needs to be converted to application user to update the custom field value? and how would i do that... thanks

1 vote
Brad Mace [ATS] November 1, 2016

In the latest version of ScriptRunner, if you're creating a simple script rather than a listener class, it appears you need to initialize the log object yourself:

 

def log = Logger.getLogger("com.example.script")
log.setLevel(Level.DEBUG)


log.info("...")
1 vote
David Keane May 29, 2015

You need to look at the server log files where JIRA is running, System.out.print will appear there. I found my logs in catalina.out for example, apache

 

0 votes
Henning Tietgens
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.
June 17, 2013

Is there a reason why you use myIssue and issue in your source?

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.
June 17, 2013

Is this jira 6? Possibly there is a bug in isUserInProjectRole in jira 6.

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