Way*_*ner 6 mercurial groovy jenkins
我试图让 Jenkins 从 BitBucket 克隆我的 mercurial 项目。它不会,因为它说凭据有问题 - 好吧,bitbucket 拒绝 Jenkins 提供的任何内容。
我几乎 100% 肯定 Jenkins 没有提供它应该提供的东西,因为当我运行时
hg clone --ssh="ssh -i /path/to/my/key" ssh://hg@bitbucket.org/my-org/my-repo
Run Code Online (Sandbox Code Playgroud)
它克隆了一个-OK。内容/path/to/my/key是我放入 Jenkins 凭证管理器中的密钥中的内容。我已经验证它是在我的 jenkinscredentials.xml文件中找到的。
而且然而,当我尝试运行我的工作?克隆失败,因为
remote: Host key verification failed.
Run Code Online (Sandbox Code Playgroud)
这让我相信问题在于通过 mercurial 插件传递的任何内容。但是我在日志中看不到它,因为它是某种掩码字符串并且只显示为******.
所以我想确保进入 Hg 插件的凭据实际上是我的credentials.xml文件中存在的凭据。
到目前为止,我已经到了这里:
import com.cloudbees.plugins.credentials.CredentialsProvider
import com.cloudbees.plugins.credentials.common.StandardUsernameCredentials
def creds = CredentialsProvider.all()
print creds
Run Code Online (Sandbox Code Playgroud)
这给了我一个凭证提供者列表......但我不确定下一步要去哪里。我一直在试图弄清楚如何获得我想要的凭证信息的文档中淹没......但没有骰子。
(如何)我可以使用我所拥有的并在 Groovy 脚本控制台中显示我的 Jenkins 凭据列表吗?
Oli*_*ain 20
这对我来说非常有效......
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("")
}
Run Code Online (Sandbox Code Playgroud)
我想要一份可用凭据的列表,并发现了这个:
def creds = com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials( com.cloudbees.plugins.credentials.common.StandardUsernameCredentials.class, Jenkins.instance, null, null );
for (c in creds) {
println(c.id + ": " + c.description)
}
Run Code Online (Sandbox Code Playgroud)
从这里得到它: https://wiki.jenkins-ci.org/display/JENKINS/Printing+a+list+of+credentials+and+their+IDs
这是一个组合脚本,将有关该主题的多个发现连接在一起。它列出了 Jenkins 所有范围的所有凭据,而不仅仅是根范围。希望它有帮助。
import com.cloudbees.plugins.credentials.Credentials
Set<Credentials> allCredentials = new HashSet<Credentials>();
def creds = com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials(
com.cloudbees.plugins.credentials.Credentials.class
);
allCredentials.addAll(creds)
Jenkins.instance.getAllItems(com.cloudbees.hudson.plugins.folder.Folder.class).each{ f ->
creds = com.cloudbees.plugins.credentials.CredentialsProvider.lookupCredentials(
com.cloudbees.plugins.credentials.Credentials.class, f)
allCredentials.addAll(creds)
}
for (c in allCredentials) {
println(c.id)
if (c.properties.username) {
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("")
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11618 次 |
| 最近记录: |