如何通过Rest API获取Jenkins的凭据ID列表
我已经阅读了"在Jenkins中动态创建作业 QnA,并且知道如何通过"
I've already read "Create Job Dynamically in Jenkins" QnA, and known how to get the information for a known credentialsId in xml format by "http://your_jenkins/credentials/store/system/domain/_/credential/503bcfce-4197-488d-be45-456623876087/api/xml" rest api.
但是我想通过rest api获取总的certificateId列表.
But I want to get the total credentialsId list by rest api.
请让我知道该怎么做.
I've finally inferred an answer from the following post: update Jenkins credentials by script
感谢您的托马斯列维".
Thank you for "Thomasleveil".
过程如下:
1)安装Scriptler插件并重新启动Jenkins服务器.
1) Install Scriptler plugin and restart Jenkins server.
2)单击侧面菜单中的脚本编辑器".
2) Click Scriptler in side menu.
3)单击添加新脚本.
3) Click Add a new Script.
4)填写表格.
The script is from "https://wiki.jenkins-ci.org/display/JENKINS/Printing+a+list+of+credentials+and+their+IDs", but run itself straightly and you can see the error messages: "groovy.lang.MissingPropertyException: No such property: Jenkins for class: Script1 ... ".
此错误已通过以下网址解决:" Jenkins的运行Groovy命令使用Groovy脚本插件"帖子.
This error has solved at "Running Groovy command from Jenkins using Groovy script plugin" post.
所以您的脚本就像:
import jenkins.model.Jenkins
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)
}
import jenkins.model.Jenkins
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)
}
5)键入" http://your_jenkins/scriptler/run/getCredentialsIdList.groovy 在浏览器网址栏中.
5) Type "http://your_jenkins/scriptler/run/getCredentialsIdList.groovy" in your browser url bar.
您可以从您的jenkins服务器上看到总的ids列表.
You can see the list of total credentialsIds from your jenkins server.
享受~~~