Jenkins常用接口汇总
由于Jenkins尚未提供官方的接口列表,以下接口来自度娘和谷姐的吐血整理:
通过restTemplate可实现Jenkins常用接口的调用:
1.1.创建任务
curl -X POST http://www.xxx.xxx/jenkins/createItem?name=JavaStd --user user:password --data-binary “@javastd.config.xml” -H “Content-Type: text/xml”
注意:认证信息和Content-Type要放在headers中,xml文件要经二进制转换后放在body中。
1.2.禁用任务
curl -X POST http://www.xxx.xxx/jenkins/job/JavaStd/disable --user user:password
1.3.启用
curl -X POST http://www.xxx.xxx/jenkins/job/JavaStd/enable --user user:password
1.4.删除任务
curl -X POST http://www.xxx.xxx/jenkins/job/JavaStd/doDelete --user user:password
1.5.获取项目描述
curl -X GET http://www.xxx.xxx/jenkins/job/JavaStd/description --user user:password
1.6.获取配置文件
curl -X GET http://www.xxx.xxx/jenkins/job/JavaStd/config.xml --user user:password
1.7.触发SCM检查
curl -X GET http://www.xxx.xxx/jenkins/job/JavaStd/polling --user user:password
1.8.普通触发
curl -X POST http://www.xxx.xxx/jenkins/job/JavaStd/build --user user:password
1.9.带参数触发
curl -X GET “http://www.xxx.xxx/jenkins/job/helloworld-freestyle/buildWithParameters?bAllTest=&Choices=2&strParam=abc” --user peterguo:peterguo
1.10.带文件触发
curl -X POST “http://www.xxx.xxx/job/Demo/buildWithParameters?assertMethod=online” -F “input=@atest.txt”
1.11.参数和补丁触发
curl -X POST “http://www.xxx.xxx/jenkins/job/helloworld-freestyle/buildWithParameters?bAllTest=&Choices=2&strParam=abc” --user user:password -F “action=upload” -F “patch.diff=@OtherTest.java.patch”
1.12.添加系统凭证
用户名和密码凭证:
curl -X POST ‘http://username:passowrd@www.xxx.xxx/xxx/credentials/store/system/domain/_/createCredentials’
–data-urlencode ‘json={
“”: “0”,
“credentials”: {
“scope”: “GLOBAL”,
“id”: “id”,
“username”: “usr”,
“password”: “bar”,
“description”: “linda”,
“$class”: “com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl”
}
}’
用户名和私钥凭证
curl -X POST ‘http://username:password@www.xxx.xxx/xxx/credentials/store/system/domain/_/createCredentials’
–data-urlencode ‘json={
“”: “0”,
“credentials”: {
“scope”: “GLOBAL”,
“id”: “”,
“passphrase”: “”,
“username”: “zhang”,
“password”: “1qaz”,
“privateKeySource”: {
“stapler-class”: “com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey$DirectEntryPrivateKeySource”,
“privateKey”: “-----BEGIN RSA PRIVATE KEY-----abc-----END RSA PRIVATE KEY-----”
},
“description”: “test”,
“stapler-class”: “com.cloudbees.jenkins.plugins.sshcredentials.impl.BasicSSHUserPrivateKey”
}
}’
1.13获取凭证列表
curl -X GET http://www.xxx.xxx/credentials/store/system/domain/_/api/json?depth=1 --user username:password
1.14删除指定凭证
curl -X GET http://www.xxx.xxx/credentials/store/system/domain/_/api/json?depth=1 --user username:password
1.15创建视图
curl -X POST http://www.xxx.xxx/jenkins/createView?name=JavaStd --user user:password --data-binary “@javastd.config.xml” -H “Content-Type: text/xml”
1.16获取视图信息
curl -X GET http://www.xxx.xxx/jenkins/view/JavaStd/config.xml --user user:password