How to Automatically deactivate inactive JIRA users

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

This widget could not be displayed.

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.

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?

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

Well now the Page is updated

What page?

Refer to your code for what?

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?

 

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
Community showcase
Published Aug 22, 2018 in Marketplace Apps

How a Marketplace app tech team is achieving gender diversity

Hello! My name is Genevieve Blanch, and I'm the Marketing Manager at RefinedWiki, creators of apps to give teams the tools to customize Atlassian platforms. Currently, 44% of the tech team at Re...

507 views 3 18
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you