I am not a strong script writer so I am looking for someone to provide me a script that I can run each night to look for users who have not logged in in the last 60 days and remove them from the jira-users group so they no longer take a license up. I have ScriptRunner. I have found other scripts out there to de-activate users, but those scripts don't work for me because of our AD/LDAP setup. So I just want to remove the inactive from the jira-users group. I would be SO GREATFUL for someone to provide me a script to do this by username. We have Jira 8.19.
@Mirco Fabbri Provided the answer in a different write up: https://community.atlassian.com/t5/Adaptavist-questions/Scriptrunner-deactivate-inactive-users-script-needs-to-be/qaq-p/914110?utm_source=atlcomm&utm_medium=email&utm_campaign=immediate_general_reply&utm_content=topic
Here is the script he provided...
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.login.LoginManager
import java.text.SimpleDateFormat;
import com.atlassian.crowd.embedded.api.CrowdService
import com.atlassian.crowd.embedded.api.UserWithAttributes
import com.atlassian.jira.bc.user.UserService
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.event.type.EventDispatchOption
def userUtil = ComponentAccessor.userUtil
def userManager = ComponentAccessor.userManager
def groupManager = ComponentAccessor.getGroupManager();
def loginManager = ComponentAccessor.getComponentOfType(LoginManager.class)
CrowdService crowdService = ComponentAccessor.crowdService
def maxDays = 90 // maximum number of days you will allow
def excludedGroups = [ // only externals
"jira-administrators",
"jira-system-administrators"
]
long count = 0;
def list
def lastlogin
def output = "Display Name; Username; Email; Last Login <br>"
def today = new Date()
def lastLogin
SimpleDateFormat df = new SimpleDateFormat("dd.MM.yy hh:mm")
userManager.getUsers().each { // loop through every user
list = true;
groupManager.getGroupNamesForUser(it).each { // loop through his groups
if (excludedGroups.contains(it)) { // if at least one group is in the list, add user
list = false;
}
}
if(list && it.isActive()) { //check if user is active & supposed to be listed
UserWithAttributes user = crowdService.getUserWithAttributes(it.getName())
Long lastLoginTime = loginManager.getLoginInfo(it.username).getLastLoginTime()
lastlogin = "Never Logged In"
if(lastLoginTime != null) {
Date date = new Date(lastLoginTime)
lastlogin = df.format(date)
}
if(lastLoginTime != null && groovy.time.TimeCategory.minus(new Date(), new Date(lastLoginTime)).days > maxDays) {
userUtil.removeUserFromGroup(ComponentAccessor.groupManager.getGroup("jira-software-user"), it)
output += "${it.getDisplayName()}; ${it.getUsername()}; ${it.getEmailAddress()}; ${lastlogin};<br>"
count++
}
}
}
output
Hi @kdickason
Glad you asked this,
you can consider using the miniOrange Bulk User management plugin for JIRA.
There, you can find a variety of features regarding user management such as deactivating inactive users (the same requirement you have), you can also perform bulk operations on the users (which native Jira user management does not support) You can import or export users and auto deactivate users who have never logged in. On top of that, if you need
any custom features, we also provide tailor-made solutions just for your requirements.
Check out the plugin here. https://marketplace.atlassian.com/apps/1224360/mo-bulk-user-management-deactivate-inactive-users-for-jira?hosting=datacenter&tab=overview
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @kdickason
You can refer to https://library.adaptavist.com/entity/remove-specified-users-from-a-group and tweek it for removing the users from the group jira-users
To get the inactive users, as mentioned in the page, you can refer to https://library.adaptavist.com/entity/deactivate-idle-users to get the list of users with some more tweeks.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Fazila Ashraf ,
Is it possible to get inactive users in Jira Cloud using the script Runner addon?
Regards,
Prasad E
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Haven't done that in cloud but a quick search got me this free plugin that could help with this use case https://marketplace.atlassian.com/apps/1224410/manage-users-for-jira-cloud?tab=overview&hosting=cloud
Hope it helps... Let me know
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Prasad Eda ,
Did you find/created the script to inactive users in Jira Cloud using the script Runner addon?
I am also looking for the same in Jira cloud using Script Runner.
Thanks,
Alok
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Same - looking for this Jira Cloud version of the Script Runner code.
Looking through Adaptavist library there aren't many scripts for the cloud.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You can't do this in Jira Cloud - users and groups are maintained in Atlassian Access, or Atlassian Admin if you don't have Access. You would need to look for a solution that can do site admin.
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.
Hi @Olivia Case
If you're looking for an easy way to automatically deactivate inactive users, you can install this app from the marketplace:
It will deactivate all inactive users you have periodically by the time you choose.
It's secure and uses Atlassian's Api's only
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.