如何通过Rest API获取Jenkins的凭据ID列表 [英] How to get the list of credentialsId of Jenkins by rest api

查看:437
本文介绍了如何通过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.

享受~~~

这篇关于如何通过Rest API获取Jenkins的凭据ID列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆