Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-71746

I cant list users assiened roles in jenkins groovy script

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}}

            mawinter69 Markus Winter
            ahmedgamal Ahmed
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: