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

Active Choices Reactive Parameter can't access Mask Passwords (Global name/password pairs)

    Details

    • Similar Issues:

      Description

      Under "Manage Jenkins / Configure System",
      I configured "Mask Passwords - Parameters to automatically mask" for:
      Active Choices Reactive Reference Parameter
      Active Choices Reactive Parameter
      Active Choices Parameter

      and created one "Mask Passwords - Global name/password pairs" for:
      build_password

      In Jenkins job configuration,
      I have an "Active Choices Reactive Parameter" using Groovy script
      and tries to use that global variable ${build_password}:

      if ( SVN_FOLDER.endsWith("/trunk") ){
          return ["N/A"]
      } else {
          def SVN_LIST_URL = "${SVN_ROOT}/${SVN_FOLDER}"
          def SVN_CMD_ARG = "svn ls --username build --password ${build_password} --non-interactive ${SVN_LIST_URL}"
          def SVN_CMD_OUT = SVN_CMD_ARG.execute().text
          def SVN_SELECCTION_LIST = SVN_CMD_OUT.split('/\n').toList().sort().reverse()
      
          return SVN_SELECCTION_LIST
      }
      

      The above code works only if I replace ${build_password} with actual password string.

        Attachments

          Activity

          Hide
          kinow Bruno P. Kinoshita added a comment -

          Righto, coming back to this issue now.

          Set up a job again with the instructions provided in the issue description. I get a build_password is not defined for the Groovy script.

          The Mask Password Plugin has a build wrapper, that uses the build_password. It is not available to any parameters, only during build time.

          Show
          kinow Bruno P. Kinoshita added a comment - Righto, coming back to this issue now. Set up a job again with the instructions provided in the issue description. I get a build_password is not defined for the Groovy script. The Mask Password Plugin has a build wrapper, that uses the build_password. It is not available to any parameters, only during build time.
          Hide
          kinow Bruno P. Kinoshita added a comment -

          So in the end there is no easy way to integrate the plug-in in a transparent way to users. Users that want to use the global parameters defined in the Mask Password Plug-in need to implement the logic in their scripts.

          I followed the logic in the plug-in code (in special this part).

          And here's one way to get it to work.

          import com.michelin.cio.hudson.plugins.maskpasswords.*;
          
          SVN_ROOT = "https://server.com/svn/root"
          
          // getting global masked password...
          maskPasswordsConfig = MaskPasswordsConfig.getInstance()
          varPasswordPairs = maskPasswordsConfig.getGlobalVarPasswordPairs()
          
          // default to empty
          build_password = ''
          // check if we have a global pair with that password
          varPasswordPairs.each { pair ->
              if (pair.getVar().equals("build_password")) {
                  // this will use Jenkins' Secret class to decrypt it...
                  build_password = pair.password
              }
          }
          
          if ( SVN_FOLDER.endsWith("/trunk") ){
              return ["N/A"]
          } else {
              def SVN_LIST_URL = "${SVN_ROOT}/${SVN_FOLDER}"
              //def SVN_CMD_ARG = "svn ls --username build --password ${build_password} --non-interactive ${SVN_LIST_URL}"
              //def SVN_CMD_OUT = SVN_CMD_ARG.execute().text
              //def SVN_SELECTION_LIST = SVN_CMD_OUT.split('/\n').toList().sort().reverse()
              // Just for test, as it would be hard to share an example calling user+pass from a repo
              def SVN_SELECTION_LIST = [build_password]
          
              return SVN_SELECTION_LIST
          }
          

          Simplified the script a little bit as it would be too hard to provide an example that worked. But in summary, you have to get that password value programmatically in Groovy.

          Added a tutorial for this integration here: http://biouno.org/tutorials/active-choices/using-masked-passwords-with-the-active-choices-plugin

          Show
          kinow Bruno P. Kinoshita added a comment - So in the end there is no easy way to integrate the plug-in in a transparent way to users. Users that want to use the global parameters defined in the Mask Password Plug-in need to implement the logic in their scripts. I followed the logic in the plug-in code (in special this part ). And here's one way to get it to work. import com.michelin.cio.hudson.plugins.maskpasswords.*; SVN_ROOT = "https: //server.com/svn/root" // getting global masked password... maskPasswordsConfig = MaskPasswordsConfig.getInstance() varPasswordPairs = maskPasswordsConfig.getGlobalVarPasswordPairs() // default to empty build_password = '' // check if we have a global pair with that password varPasswordPairs.each { pair -> if (pair.getVar().equals( "build_password" )) { // this will use Jenkins' Secret class to decrypt it... build_password = pair.password } } if ( SVN_FOLDER.endsWith( "/trunk" ) ){ return [ "N/A" ] } else { def SVN_LIST_URL = "${SVN_ROOT}/${SVN_FOLDER}" //def SVN_CMD_ARG = "svn ls --username build --password ${build_password} --non-interactive ${SVN_LIST_URL}" //def SVN_CMD_OUT = SVN_CMD_ARG.execute().text //def SVN_SELECTION_LIST = SVN_CMD_OUT.split( '/\n' ).toList().sort().reverse() // Just for test, as it would be hard to share an example calling user+pass from a repo def SVN_SELECTION_LIST = [build_password] return SVN_SELECTION_LIST } Simplified the script a little bit as it would be too hard to provide an example that worked. But in summary, you have to get that password value programmatically in Groovy. Added a tutorial for this integration here: http://biouno.org/tutorials/active-choices/using-masked-passwords-with-the-active-choices-plugin
          Hide
          totoroliu Rick Liu added a comment -

          thank you Bruno for your support

          Show
          totoroliu Rick Liu added a comment - thank you Bruno for your support
          Hide
          nels4784 Jeffrey Nelson added a comment -

          Thanks Bruno - this also really helped me out!

          Show
          nels4784 Jeffrey Nelson added a comment - Thanks Bruno - this also really helped me out!
          Hide
          mishvik vikas Mishra added a comment -

          Thank you Bruno. 

          Show
          mishvik vikas Mishra added a comment - Thank you Bruno. 

            People

            • Assignee:
              kinow Bruno P. Kinoshita
              Reporter:
              totoroliu Rick Liu
            • Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: