How to Automatically deactivate inactive JIRA users

Utkarsh Agarwal February 2, 2017

How can i add Escalation service in script runner to perform this job daily as mentioned in the link:  https://www.adaptavist.com/doco/display/SFJ/Automatically+deactivate+inactive+JIRA+users

I mean what should be the contents for: 

JQL Query:

Userkey:

cron expression:

additional issue action:

1 answer

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.
February 2, 2017

Escalation service takes a JQL function and does something for each issue.

The page you found there is wrong - it does not relate to escalation service. You can run it in the script console or as a service.

Utkarsh Agarwal February 3, 2017

Well now the Page is updated. I don't think its because of my Query or is it?

Well I tried what is now mentioned to run the script as a service. But before i run the actual script I tried a basic one to deactivate user from a group.:

import com.atlassian.crowd.embedded.api.User
import com.atlassian.crowd.embedded.impl.ImmutableUser
import com.atlassian.jira.bc.user.UserService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.util.UserManager
import org.apache.log4j.Level
import org.apache.log4j.Logger

Logger log = log
log.setLevel(Level.INFO)

UserManager userManager = ComponentAccessor.getUserManager()
UserService userService = ComponentAccessor.getComponent(UserService.class)
User updateUser
UserService.UpdateUserValidationResult updateUserValidationResult

def errors = ''
ComponentAccessor.getUserUtil().getAllUsersInGroupNamesUnsorted(['jira-inactive-users']).each { user ->
updateUser = ImmutableUser.newUser(user).active(false).toUser()
updateUserValidationResult = userService.validateUpdateUser(updateUser)
if (updateUserValidationResult.isValid()) {
userService.updateUser(updateUserValidationResult)
} else {
errors += "Update of ${user.name} failed: ${updateUserValidationResult.getErrorCollection().getErrors().entrySet().join(',')}\n"
}
}
return errors
log.info "${report}"

 

It seems that the service is not running the above code. I have created xyz.groovy file for above code and placed it under jira_home/scripts directory. No logs can be seen in atlassian-jira.log files either.

Can you help me out here?

Utkarsh Agarwal February 3, 2017

Sorry wrong code. Please refer below:

import com.atlassian.crowd.embedded.api.User
import com.atlassian.crowd.embedded.impl.ImmutableUser
import com.atlassian.jira.bc.user.UserService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.util.UserManager
import org.apache.log4j.Level
import org.apache.log4j.Logger

Logger log = log
log.setLevel(Level.INFO)

UserManager userManager = ComponentAccessor.getUserManager()
UserService userService = ComponentAccessor.getComponent(UserService.class)
User updateUser
UserService.UpdateUserValidationResult updateUserValidationResult

def errors = ''
def report = ''

ComponentAccessor.getUserUtil().getAllUsersInGroupNamesUnsorted(['jira-inactive-users']).each { user ->
updateUser = ImmutableUser.newUser(user).active(false).toUser()
updateUserValidationResult = userService.validateUpdateUser(updateUser)
report += "${user.name},"
if (updateUserValidationResult.isValid()) {
userService.updateUser(updateUserValidationResult)
} else {
errors += "Update of ${user.name} failed: ${updateUserValidationResult.getErrorCollection().getErrors().entrySet().join(',')}\n"
}
}
log.info "${report}"
return errors

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.
February 3, 2017

Well now the Page is updated

What page?

Refer to your code for what?

Utkarsh Agarwal February 5, 2017

Following Page: https://www.adaptavist.com/doco/display/SFJ/Automatically+deactivate+inactive+JIRA+users

>Refer to your code for what?

It seems that the service is not running the above code. I have created xyz.groovy file for above code and placed it under jira_home/scripts/ directory. No logs can be seen in atlassian-jira.log files either.

Can you help me out here?

 

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.
February 12, 2017

Did you set up a service for it? Did you read the link I posted: https://scriptrunner.adaptavist.com/latest/jira/services.html

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events