Just a heads up: On March 24, 2025, starting at 4:30pm CDT / 19:30 UTC, the site will be undergoing scheduled maintenance for a few hours. During this time, the site might be unavailable for a short while. Thanks for your patience.
×Hi,
I'm looking for a groovy script that will give me a list of users that are currently logged in to Jira. In the Scriptrunner console, I can get a list of all users or users that have never logged in but I don't see a way to get just users that are logged in right now ("right now" = when I run the script in the console).
Thanks in advance for any help.
- B
Hi,
you can retrieve all application users.
And getting the last login time of user compares it with a delay (like 1 hour ago).
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.util.UserManager
import com.atlassian.jira.security.login.LoginManager
import groovy.time.TimeCategory
def twoHoursAg
use(TimeCategory) {
twoHoursAgo = 1.hours.ago
}
UserManager userManager = ComponentAccessor.getUserManager()
LoginManager loginManager = ComponentAccessor.getComponent(LoginManager)
userManager.users.findAll{loginManager.getLoginInfo(it.username)?.lastLoginTime!=null && new Date(loginManager.getLoginInfo(it.username)?.lastLoginTime) >= twoHoursAgo}
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.