我试图让 Jenkins 从 BitBucket 克隆我的 mercurial 项目。它不会,因为它说凭据有问题 - 好吧,bitbucket 拒绝 Jenkins 提供的任何内容。
我几乎 100% 肯定 Jenkins 没有提供它应该提供的东西,因为当我运行时
hg clone --ssh="ssh -i /path/to/my/key" ssh://hg@bitbucket.org/my-org/my-repo
它克隆了一个-OK。
/path/to/my/key
的内容是我在 Jenkins 的凭证管理器中放入的 key 。我已经验证它是在我的 jenkins 中找到的 credentials.xml
文件。然而,当我尝试运行我的工作时?克隆失败,因为
remote: Host key verification failed.
这让我相信问题在于通过 mercurial 插件传递的任何内容。但我无法在日志中看到它,因为它是某种 masked string并仅显示为
******
.所以我想确保进入 Hg 插件的凭据实际上是我的
credentials.xml
中存在的凭据。文件。到目前为止,我已经到了这里:
import com.cloudbees.plugins.credentials.CredentialsProvider
import com.cloudbees.plugins.credentials.common.StandardUsernameCredentials
def creds = CredentialsProvider.all()
print creds
这给了我一个凭证提供者列表......但我不确定下一步要去哪里。我一直在试图弄清楚如何获得我想要的凭证信息的文档中淹没......但没有骰子。
(如何)我可以使用我所拥有的并在 Groovy 脚本控制台中显示我的 Jenkins 凭据列表吗?
最佳答案
这对我来说非常有效......
def creds = com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials(
com.cloudbees.plugins.credentials.Credentials.class
)
for (c in creds) {
println(c.id)
if (c.properties.description) {
println(" description: " + c.description)
}
if (c.properties.username) {
println(" username: " + c.username)
}
if (c.properties.password) {
println(" password: " + c.password)
}
if (c.properties.passphrase) {
println(" passphrase: " + c.passphrase)
}
if (c.properties.secret) {
println(" secret: " + c.secret)
}
if (c.properties.privateKeySource) {
println(" privateKey: " + c.getPrivateKey())
}
println("")
}
关于jenkins - 如何在脚本控制台中列出我的所有 Jenkins 凭据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34795050/