Issue
How to get a list of users who does not have Admin privilege ( Groovy + jenkins)
def inst = Jenkins.getInstanceOrNull()
def strategy = inst.getAuthorizationStrategy()
def adminUserList = User.getAll().findAll { user ->
strategy.hasPermission(user.id, Jenkins.ADMINISTER)
}
This is giving me a list of users who has ADMINISTER privilege. How to retrieve the list of all users who does not have ADMINISTER privilege.
Solution
A simple negation helped to get the expected output :
def inst = Jenkins.getInstanceOrNull()
def strategy = inst.getAuthorizationStrategy()
def adminUserList = User.getAll().findAll { user ->
!strategy.hasPermission(user.id, Jenkins.ADMINISTER)
}
Just changed "strategy.hasPermission" to "!strategy.hasPermission", this has given the expected output.
Answered By - arjun
Answer Checked By - Senaida (JavaFixing Volunteer)