def getPassword = { username ->
def creds = com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials(
com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials.class,
jenkins.model.Jenkins.instance
)
def c = creds.findResult { it.username == username ? it : null }
if ( c ) {
println "found credential ${c.id} for username ${c.username}"
def credentials_store = jenkins.model.Jenkins.instance.getExtensionList(
'com.cloudbees.plugins.credentials.SystemCredentialsProvider'
)[0].getStore()
println "result: " + credentials_store
} else {
println "could not find credential for ${username}"
}
}
getPassword("XYZ")
Run Code Online (Sandbox Code Playgroud)
但现在我想获得相应用户的密码,我无法做到...
如果我尝试访问passord等,我总是会得到未知的方法等.
这样做的原因是使用此用户/密码来调用git并从存储库中提取信息.
我总是得到这样的东西:
result: com.cloudbees.plugins.credentials.SystemCredentialsProvider$StoreImpl@1639eab2
Run Code Online (Sandbox Code Playgroud)
在用它进行了更多的实验(以及Jeanne Boyarsky的暗示)后,我发现我正在考虑编译.以下内容已经为我提供了用户的密码:
def getUserPassword = { …Run Code Online (Sandbox Code Playgroud)