How to get the list of credentialsId of Jenkins by rest api

跟風遠走 提交于 2019-12-23 05:03:25

问题


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.

But I want to get the total credentialsId list by rest api.

Please let me know how to do that if you know that.


回答1:


I've finally inferred an answer from the following post: update Jenkins credentials by script

Thank you for "Thomasleveil".

The procedure is as followings:

1) Install Scriptler plugin and restart Jenkins server.

2) Click Scriptler in side menu.

3) Click Add a new Script.

4) Fill the form.

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 ... ".

This error has solved at "Running Groovy command from Jenkins using Groovy script plugin" post.

So your script is like:

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) Type "http://your_jenkins/scriptler/run/getCredentialsIdList.groovy" in your browser url bar.

You can see the list of total credentialsIds from your jenkins server.

Enjoy that ~~~



来源:https://stackoverflow.com/questions/43318727/how-to-get-the-list-of-credentialsid-of-jenkins-by-rest-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!