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

0 vote

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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Bridget Sauer
Published yesterday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

60 views 0 3
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