Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Receive Error when I run the script to remove inactive users from JIRA through Script Runner console

Bhavin Sanghvi June 4, 2019

I am running the below script in Script Console of Script Runner. Do i need to configure or add something to the below Script.

The Script will remove users who have not used JIRA since last 3 months.

 

import com.atlassian.confluence.security.PermissionManager
import com.atlassian.confluence.security.login.LoginManager
import com.atlassian.confluence.user.UserAccessor
import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.user.UserManager
import groovy.time.TimeCategory

def userManager = ComponentLocator.getComponent(UserManager)
def userAccessor = ComponentLocator.getComponent(UserAccessor)
def loginManager = ComponentLocator.getComponent(LoginManager)
def permissionManager = ComponentLocator.getComponent(PermissionManager)

def threeMonthsBack
use(TimeCategory) {
threeMonthsBack = 3.months.ago
}
def users = userManager.users

def page = users.currentPage

while (true) {

page.each { user ->

if (userAccessor.isDeactivated(user)) {
return
}

log.debug(user)
def userLoginInfo = loginManager.getLoginInfo(user)
def lastSuccessfulLoginDate = userLoginInfo?.lastSuccessfulLoginDate

def toDeactivate = ! lastSuccessfulLoginDate || lastSuccessfulLoginDate < threeMonthsBack
if (toDeactivate) {
log.warn "Found user: ${user.name} with last login date ${lastSuccessfulLoginDate}, will deactivate"
return

if (!permissionManager.isSystemAdministrator(user)) {
log.info "Deactivating user.."
userAccessor.deactivateUser(user)
}
}
}

if (users.onLastPage()) {
return
}
else {
users.nextPage()
}
}

 

I receive the below error.

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script1.groovy: 4: unable to resolve class com.atlassian.sal.api.component.ComponentLocator
@ line 4, column 1.
import com.atlassian.sal.api.component.ComponentLocator
^

Script1.groovy: 2: unable to resolve class com.atlassian.confluence.security.login.LoginManager
@ line 2, column 1.
import com.atlassian.confluence.security.login.LoginManager
^

Script1.groovy: 1: unable to resolve class com.atlassian.confluence.security.PermissionManager
@ line 1, column 1.
import com.atlassian.confluence.security.PermissionManager
^

Script1.groovy: 5: unable to resolve class com.atlassian.user.UserManager
@ line 5, column 1.
import com.atlassian.user.UserManager
^

Script1.groovy: 3: unable to resolve class com.atlassian.confluence.user.UserAccessor
@ line 3, column 1.
import com.atlassian.confluence.user.UserAccessor
^

5 errors

at com.adaptavist.sr.cloud.workflow.AbstractScript.parseScript(AbstractScript.groovy:51)
at com.adaptavist.sr.cloud.workflow.AbstractScript.evaluate(AbstractScript.groovy:32)
at com.adaptavist.sr.cloud.workflow.AbstractScript$evaluate$0.callCurrent(Unknown Source)
at com.adaptavist.sr.cloud.events.ScriptExecution.run(ScriptExecution.groovy:27)
at ConsoleScriptExecution1_groovyProxy.run(Unknown Source)

 

 

Can anyone please help me out to fix this

 

 

1 answer

0 votes
Mark Markov
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 5, 2019

Hello @Bhavin Sanghvi 

It seems you are trying to use script for confluence.

Try this example for JIRA.

Hope it helps!

Bhavin Sanghvi June 5, 2019

@Mark Markov - I tried the script in the link you provided but its the same issue.

1. How do i resolve the warnings i receive on the Script Console.

2. I receive the same error message when i try to run the script as Current user.

 

Script_Console_error.png

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events