I want to list all users in jenkins, via the console script that jenkins has.

So far I managed to list all the users using this:

import hudson.model.User   
User.getAll().each { user ->   
   println user}

but they are listed by the first and last name, which I don't need...

I would like to list them by their user IDs, can you give me a hand?

I looked through the documentation but I fail to understand how to use it the right way. I'm not so experimented with groovy scripting..

Any ideas? Thank you!

2 Answers 2


According to the hudson.modle.User documentation, you can use the getId() method to get the user's id.

Probably like that:

import hudson.model.User
User.getAll().each { user ->
println user.getId()}

First, sorry for posting this on ask ubuntu instead of serverfault.

I found the perfect way:

import hudson.model.User   
import jenkins.model.Jenkins   
def realm = Jenkins.getInstance().getSecurityRealm()   
def users = realm.getAllUsers()   
for (User u : users) {   
    def userid = u.getId()   
    println(userid + " ")   

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .