I cant list users assiened roles in jenkins groovy script

This issue is archived. You can view it, but you can't modify it. Learn more

XMLWordPrintable

      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 becouse I cant list users assiened roles with groovy

      this example using user names but i need to know how to apply same concept with 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}

      }

            Assignee:
            Markus Winter
            Reporter:
            Ahmed
            Archiver:
            Jenkins Service Account

              Created:
              Updated:
              Resolved:
              Archived: