2

This is similar to how to get all the jenkins users through api, but that provides the list of ALL users, not the users who can actually log in to Jenkins, which is listed under https://[JENKINS]/securityRealm/.

How do you get the list of users that can login to jenkins via an API call? In other words, how do you get the list of users under https://[JENKINS]/securityRealm/ via an API call?

Thanks!

grayaii
  • 2,241
  • 7
  • 31
  • 47
  • Do you need this via the web API or from a Jenkinsfile? – zett42 Feb 23 '20 at 16:18
  • Ideally web API but if worse comes to worse I can make it work with a Jenkins file via a groovy script. In fact I can make it work with any sort of thing I can automate :) – grayaii Feb 23 '20 at 20:08

1 Answers1

3

Class HudsonPrivateSecurityRealm has a method getAllUsers() which is documented as

All users who can login to the system.

Groovy code sample:

Hudson.instance.getSecurityRealm().getAllUsers().each { 
    println it 
}
zett42
  • 25,437
  • 3
  • 35
  • 72