How to give user access for parameters in Jenkins basused on user role in Role-based Authorization Strategy plugin

I want to give user access for parameters in Jenkins basused on user role.

so I am using Role-based Authorization Strategy and Active Choices parameter plugins and trying to do this and I successfully gave user access for parameters based on user name but not based on user roles.

I want to do the same based on user roles.

import jenkins.model.Jenkins 
import hudson.model.User  

// Get the current user 
User currentUser = User.current()  

// Get the username of the current user 
String currentUsername = currentUser != null ? currentUser.fullName : null 

// Define the available environments based on usernames 
def envChoices = []  

if (currentUsername == "DevUser1") {
 envChoices += "DEV" 
if (currentUsername == "QAUser1") {
 envChoices += "QA" 
// Check if the user has the role "admin" to list all parameters (DEV, QA, PROD) if (currentUsername == "Admin") { envChoices += ["DEV", "QA", "PROD"]

return envChoices

Also how to list user roles in Jenkins groovy script console does Role-based Authorization Strategy plugin have variables? I could not find it.

You can call the methods of the REST api within your groovy script.
The method doGetRole is what you need here probably.

Jenkins jenkins = Jenkins.get()
rbas = jenkins.getAuthorizationStrategy()
json = rbas.doGetRole("globalRoles", "admin")
def slurper = new JsonSlurper()
def result = slurper.parseText(json)

There is no method available that lists all roles a user belongs to.

You would also need to check if any of the groups a user belongs is in the admin role to be 100% correct.
currentUser.getAuthorities() gives you the list of groups the user belongs to.