I am trying to get the list of admin user list and also the users and their level of permissions in Jenkins.
Can anyone help me with any script available please.
I am trying to get the list of admin user list and also the users and their level of permissions in Jenkins.
Can anyone help me with any script available please.
You can retrieve all the users using groovy script as follows:
import hudson.model.User
allUsers = User.getAll()
adminList = []
for (u in allUsers) {
if (u.hasPermission(Jenkins.ADMINISTER)) {
adminList.add(u)
}
}
println(adminList)
I use the following script to create a admin user list. The script also works with Matrix-based security.
import hudson.model.User
def inst = Jenkins.getInstanceOrNull()
def strategy = inst.getAuthorizationStrategy()
def adminUserList = User.getAll().findAll { user ->
strategy.hasPermission(user.id, Jenkins.ADMINISTER)
}
All users with their permissions are accessible as follows:
import hudson.model.User
import hudson.security.Permission
def inst = Jenkins.getInstanceOrNull()
def strategy = inst.getAuthorizationStrategy()
strategy.getMetaPropertyValues().find { it.getName() == 'grantedPermissions'}.each {
// it.value is a map with permission as key and the corresponding users as value
print(it.value[Permission.READ])
print(it.value[Permission.WRITE])
print(it.value[Permission.HUDSON_ADMINISTER])
}