Can't update user via scriptrunner

aas December 8, 2020

I try to make user inactive via groovy scriptrunner 

1.import com.atlassian.jira.bc.user.UserService
2.UserService userService = ComponentAccessor.getComponent(UserService)
3.
4.try{
5.def updatedUser = userService.newUserBuilder(listForTest.get(0)).
6.displayName("${listForTest.get(0).username}_not 7.working").active(false).build()
8.def updateUserValidationResult = 9.userService.validateUpdateUser(updatedUser)
10.log.warn("Is valid : " + updateUserValidationResult.isValid())
11.userService.updateUser(updateUserValidationResult)
12.}catch (Exception e){
13.log.warn(e)
14.}
15.log.warn("Try to deactivate first user from list. This user is 16.${listForTest.get(0).username}")
17.log.warn("End of script")

 and user become inactive and name changes but I have a long list of Exceptions in script console 

at Script101.run(Script101.groovy:11) 

.

.

.

WARN [runner.ScriptBindingsManager]: Try to deactivate first user from list. This user is aantonov 

WARN [runner.ScriptBindingsManager]: End of script Start of logs truncated as they exceeded 300 lines.

But I can't find this log in atlassian-jira.log or in catalina.out on jira server

What is wrong and why that exceptions appears but user changes and why it doesn't handle by catch block?

 

2 answers

1 accepted

1 vote
Answer accepted
Tom Lister
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 8, 2020

Hi @aas 

What is your exception? In Logging and Profiling page, are there settings for 'runner.ScriptBindingsManager'? Are there any log4j properties for that category?

This is a script excerpt I use

ApplicationUserBuilder applicationUserBuilder = usrService.newUserBuilder(user);
applicationUserBuilder.active(true);

ApplicationUser userForValidation = applicationUserBuilder.build();
UserService.UpdateUserValidationResult updateUserValidationResult = usrService.validateUpdateUser(userForValidation);
if (updateUserValidationResult.isValid()) {
usrService.updateUser(updateUserValidationResult);
logit.info("internal update")
} else {
errorCollection = updateUserValidationResult.getErrorCollection();
logit.info(errorCollection)
}
aas December 8, 2020

Hi @Tom Lister 

In Logging and Profiling page I have DEBUG

StackTrace is:

at Script101.run(Script101.groovy:96) at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:317) at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:155) at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:233) at javax.script.ScriptEngine$eval.call(Unknown Source) at com.onresolve.scriptrunner.runner.AbstractScriptRunner.runScriptAndGetContext(AbstractScriptRunner.groovy:172) at com.onresolve.scriptrunner.runner.AbstractScriptRunner$runScriptAndGetContext$3.callCurrent(Unknown Source) at com.onresolve.scriptrunner.runner.AbstractScriptRunner.runScriptAndGetContext(AbstractScriptRunner.groovy:291) at com.onresolve.scriptrunner.runner.AbstractScriptRunner$runScriptAndGetContext$2.callCurrent(Unknown Source) at com.onresolve.scriptrunner.runner.AbstractScriptRunner.runScript(AbstractScriptRunner.groovy:303) at com.onresolve.scriptrunner.runner.rest.common.UserScriptEndpoint$_execFromJson_closure2.doCall(UserScriptEndpoint.groovy:156) at com.onresolve.scriptrunner.runner.rest.common.UserScriptEndpoint$_execFromJson_closure2.doCall(UserScriptEndpoint.groovy) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:101) at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:323) at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:263) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1041) at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:37) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47) at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:52) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:119) at com.onresolve.scriptrunner.runner.diag.DiagnosticsManagerImpl$DiagnosticsExecutionHandlerImpl$_execute_closure1.doCall(DiagnosticsManagerImpl.groovy:345) at com.onresolve.scriptrunner.runner.diag.DiagnosticsManagerImpl$DiagnosticsExecutionHandlerImpl$_execute_closure1.doCall(DiagnosticsManagerImpl.groovy) at sun.reflect.GeneratedMethodAccessor1351.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:101) at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:323) at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:263) at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1041) at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:37) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:119) at com.onresolve.scriptrunner.runner.ScriptExecutionRecorder.withRecording(ScriptExecutionRecorder.groovy:13) at com.onresolve.scriptrunner.runner.ScriptExecutionRecorder$withRecording.call(Unknown Source) at com.onresolve.scriptrunner.runner.diag.DiagnosticsManagerImpl$DiagnosticsExecutionHandlerImpl.execute(DiagnosticsManagerImpl.groovy:343) at com.onresolve.scriptrunner.runner.rest.common.UserScriptEndpoint.execFromJson(UserScriptEndpoint.groovy:147) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.atlassian.plugins.rest.common.interceptor.impl.DispatchProviderHelper$ResponseOutInvoker$1.invoke(DispatchProviderHelper.java:192) at com.atlassian.plugins.rest.common.interceptor.impl.DispatchProviderHelper$1.intercept(DispatchProviderHelper.java:83) at com.atlassian.plugins.rest.common.interceptor.impl.DefaultMethodInvocation.invoke(DefaultMethodInvocation.java:53) at com.atlassian.plugins.rest.common.expand.interceptor.ExpandInterceptor.intercept(ExpandInterceptor.java:41) at com.atlassian.plugins.rest.common.interceptor.impl.DefaultMethodInvocation.invoke(DefaultMethodInvocation.java:53) at com.atlassian.plugins.rest.common.interceptor.impl.DispatchProviderHelper.invokeMethodWithInterceptors(DispatchProviderHelper.java:110) at com.atlassian.plugins.rest.common.interceptor.impl.DispatchProviderHelper$ResponseOutInvoker._dispatch(DispatchProviderHelper.java:190) at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75) at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:302) at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147) at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108) at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)

...

2020-12-08 16:55:14,161 WARN [runner.ScriptBindingsManager]: Try to deactivate first user from list. This user is someUser

2020-12-08 16:55:14,162 WARN [runner.ScriptBindingsManager]: End of script

Start of logs truncated as they exceeded 300 lines.

aas December 8, 2020

But in another instance of Jira I don't have that long Stack Trace in logs in script console only that logs which I want to show:

2020-12-09 10:11:12,157 WARN [runner.ScriptBindingsManager]: Is valid : true

2020-12-09 10:11:12,371 INFO [index.MonitoringIndexWriter]: [lucene-stats] flush stats: snapshotCount=3, totalCount=14, periodSec=1852, flushIntervalMillis=617533, indexDirectory=null, indexWriterId=com.atlassian.jira.index.MonitoringIndexWriter@3b051102, indexDirectoryId=RAMDirectory@2ed11bb2 lockFactory=org.apache.lucene.store.SingleInstanceLockFactory@67ca8e7c

2020-12-09 10:11:12,472 WARN [runner.ScriptBindingsManager]: Try to deactivate first user from list. This user is someUsername

2020-12-09 10:11:12,472 WARN [runner.ScriptBindingsManager]: End of script

Tom Lister
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 8, 2020

Hi @aas 

Are both servers the same version and configuration 

aas December 9, 2020

Versions of Jira same 8.5.6, version of scriptrunner the same 6.5.0-p5

log4j.properties are different, but I can't find anything in log4j.properties about logging in script console

aas December 9, 2020

You mean this stack trace is shown because of some log4j settings and not because of error? The goal is to bulk deactivate thousand users but I worry about that stack trace in console and that it was caused by this code 

usrService.updateUser(updateUserValidationResult)
aas December 9, 2020

In catalina.out and in atlassian-jira.log I can find logs that I write in script. I mean that in script I write

log.warn("Is valid : " + updateUserValidationResult.isValid())

and in catalina.out I see "Is valid : true" but there no that long stack trace that appears in script console log tab

1.png

aas December 10, 2020

I found out that if turn off logging for package com.atlassian.cache.stacktrace in "logging and profiling" there no more stacktrace in console but only my logs. What is the package com.atlassian.cache.stacktrace and why that stacktrace appears?

Tom Lister
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 10, 2020

Hi @aas 

I'm not sure what the stacktrace package is doing. It's not in the API javadoc.

0 votes
Tom Lister December 8, 2020

removed , posted by mistake

Suggest an answer

Log in or Sign up to answer