SHARE
TWEET

Untitled

a guest Dec 13th, 2016 92 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def getPassword = { username ->
  2.     def creds = com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials(
  3.         com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials.class,
  4.         jenkins.model.Jenkins.instance
  5.     )
  6.  
  7.     def c = creds.findResult { it.username == username ? it : null }
  8.  
  9.     if ( c ) {
  10.         println "found credential ${c.id} for username ${c.username}"
  11.  
  12.         def systemCredentialsProvider = jenkins.model.Jenkins.instance.getExtensionList(
  13.             'com.cloudbees.plugins.credentials.SystemCredentialsProvider'
  14.             ).first()
  15.  
  16.       def password = systemCredentialsProvider.credentials.first().password
  17.  
  18.       println password
  19.  
  20.  
  21.     } else {
  22.       println "could not find credential for ${username}"
  23.     }
  24. }
  25.  
  26. getPassword("laura")
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top