CI: Get the list of users who have accessed Jenkins using Groovy script

Akarsh Seggemu, M.Sc.
2 min readMar 24, 2024

--

In my previous article https://akarshseggemu.medium.com/ci-configuring-jenkins-to-support-azure-active-directory-ad-d497a177aafd I shared about how to configure Jenkins to support Azure Active Directory (AD). In this article I would like you to know how you can get the list of users who have accessed your Jenkins instance.

Get the list of users who have accessed Jenkins using a Groovy script,

import hudson.model.User

def allUsers = User.getAll()
allUsers.each { user ->
println(user.fullName)
}

Above script imports the User class from the hudson.model package and retrieves all the users in Jenkins using the User.getAll() method. It then iterates over each user and prints their full name in a new line.

Run this script in the Jenkins script console to get the list of users.

I have a test Jenkins which is running on http://localhost:8080/. Click on “Manage Jenkins”

Click on “Script Console”

Paste the code in “Script Console” and Click on Run.

The Result will show the users logged into the Jenkins instance

Recommended reading — https://www.jenkins.io/doc/book/managing/script-console/ for further knowing other useful features of Jenkins script console.

I hope my article helped you to understand how to get the list of users who have accessed Jenkins using Groovy script

If you like my articles, please follow me on Medium, you can also watch my videos on YouTube and you can also support me by buying me a coffee.

--

--

Akarsh Seggemu, M.Sc.

IT Team Lead | Post graduate Computer Science from TU Berlin | Telugu writings are found in this account https://medium.com/@akarshseggemu_telugu