I am trying Automatically deactivate inactive JIRA (7.1.8 ) users by using code provided link at https://www.adaptavist.com/doco/display/SFJ/Automatically+deactivate+inactive+JIRA+users
Error
No signature of method: com.atlassian.jira.bc.user.DefaultUserService.validateUpdateUser() is applicable for argument types: (com.atlassian.crowd.embedded.impl.ImmutableUser) values: [com.atlassian.crowd.embedded.impl.ImmutableUser@bec3c60c] Possible solutions: validateUpdateUser(com.atlassian.jira.user.ApplicationUser), validateCreateUser(com.atlassian.jira.bc.user.UserService$CreateUserRequest)
groovy.lang.MissingMethodException: No signature of method: com.atlassian.jira.bc.user.DefaultUserService.validateUpdateUser() is applicable for argument types: (com.atlassian.crowd.embedded.impl.ImmutableUser) values: [com.atlassian.crowd.embedded.impl.ImmutableUser@bec3c60c] Possible solutions: validateUpdateUser(com.atlassian.jira.user.ApplicationUser), validateCreateUser(com.atlassian.jira.bc.user.UserService$CreateUserRequest) at Script1$_run_closure2.doCall(Script1.groovy:32) at Script1.run(Script1.groovy:25)
Any idea what is missing or wron in this code
import com.atlassian.crowd.embedded.api.CrowdService
import com.atlassian.crowd.embedded.api.User
import com.atlassian.crowd.embedded.api.UserWithAttributes
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.UserUtil
import org.apache.log4j.Level
import org.apache.log4j.Logger
Logger log = log
log.setLevel(Level.INFO)
int numOfDays = 100 // Number of days the user was not logged in
Date dateLimit = (new Date())- numOfDays
UserUtil userUtil = ComponentAccessor.userUtil
CrowdService crowdService = ComponentAccessor.crowdService
UserService userService = ComponentAccessor.getComponent(UserService.class)
User updateUser
UserService.UpdateUserValidationResult updateUserValidationResult
long count = 0
userUtil.getUsers().findAll{it.isActive()}.each {
UserWithAttributes user = crowdService.getUserWithAttributes(it.getName())
String lastLoginMillis = user.getValue('login.lastLoginMillis')
if (lastLoginMillis?.isNumber()) {
Date d = new Date(Long.parseLong(lastLoginMillis))
if (d.before(dateLimit)) {
updateUser = ImmutableUser.newUser(user).active(false).toUser()
updateUserValidationResult = userService.validateUpdateUser(updateUser)
if (updateUserValidationResult.isValid()) {
userService.updateUser(updateUserValidationResult)
log.info "Deactivated ${updateUser.name}"
count++
} else {
log.error "Update of ${user.name} failed: ${updateUserValidationResult.getErrorCollection().getErrors().entrySet().join(',')}"
}
}
}
}
"${count} users deactivated.\n"
Hi Muhammad
The above example is for JIRA v6, for JIRA v7 there are few changes, therefore the script comp for JIRA 7 should be
import com.atlassian.crowd.embedded.api.CrowdService import com.atlassian.crowd.embedded.api.UserWithAttributes 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.ApplicationUser import com.atlassian.jira.user.ApplicationUsers import com.atlassian.jira.user.util.UserUtil int numOfDays = 100 // Number of days the user was not logged in Date dateLimit = (new Date())- numOfDays UserUtil userUtil = ComponentAccessor.userUtil CrowdService crowdService = ComponentAccessor.crowdService UserService userService = ComponentAccessor.getComponent(UserService) ApplicationUser updateUser UserService.UpdateUserValidationResult updateUserValidationResult long count = 0 userUtil.getUsers().findAll{it.isActive()}.each { UserWithAttributes user = crowdService.getUserWithAttributes(it.getName()) String lastLoginMillis = user.getValue('login.lastLoginMillis') if (lastLoginMillis?.isNumber()) { Date d = new Date(Long.parseLong(lastLoginMillis)) if (d.before(dateLimit)) { updateUser = ApplicationUsers.from(ImmutableUser.newUser(user).active(false).toUser()) updateUserValidationResult = userService.validateUpdateUser(updateUser) if (updateUserValidationResult.isValid()) { userService.updateUser(updateUserValidationResult) log.info "Deactivated ${updateUser.name}" count++ } else { log.error "Update of ${user.name} failed: ${updateUserValidationResult.getErrorCollection().getErrors().entrySet().join(',')}" } } } } "${count} users deactivated.\n"
regards, Thanos
Thanos,
Thank you for this. Very helpful.
Was wondering if there is a way to expand this script to exclude certain accounts. We have service accounts used for notifications only. These accounts never actually log into JIRA. I am hoping that if we use a standard naming convention, preference the user name with SYS-, could this script be modified to exclude accounts that begin with SYS- ? We do not want these accounts deactivated.
Thank you
Jeanne
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Jeanne,
You can update the condition to be something like
//if has not logged in for x days AND it's username does not start with the "SYS-" prefix if (d.before(dateLimit) && !it.username.startsWith("SYS-")) { //rest of the code that deactivates user }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Silly question. But can you let me know 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:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Utkarsh,
Probably you will need a ScriptRunner Service
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Utkarsh,
Apologies but the document you viewed was an old draft and incorrect. @Jamie Echlin (Adaptavist) alerted me of this discrepancy and I've since reviewed and updated it to reflect how to set this up as a JIRA Service.
I've also created an issue to update the ScriptRunner docs to include this script there too.
Regards, Mark
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am looking to add one more parameter to the script. For the JIRA 7 comp, how do I limit the users to those in the jira-users group? We have several accounts used for notification purposes only. These accounts are not in the jira-users group, thus preventing end-users from trying to log in with these accounts. The accounts will never have a "last login" but should not be deactivated.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi. I want to use this script.
But It doesn't work.
I was login use admin id. And Go Admin page -> Addon -> Script console.
And Run this code. It work.
But I go system-> Services and Run this code.
error like this
Error Messages: [You do not have the permission to update users.]
Help me ^^
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Atlassian Government Cloud has achieved FedRAMP Authorization at the Moderate level! Join our webinar to learn how you can accelerate mission success and move work forward faster in cloud, all while ensuring your critical data is secure.
Register NowOnline forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.