问题
Jenkins 使用 API 触发构建
解决
1. 获取 Token
- 登录 Jenkins
- 进入
用户
页面 - 然后看到
API Token
,点击添加
后复制
2. 使用 curl
curl -X POST -u "username:token" "http://jenkins-url/job/job-name/build?token=token"
前端调用
var jenkinsapi = require('jenkins-api');
// username/password
var jenkins = jenkinsapi.init("http://admin:token@ip:8080");
var token = "token";
jenkins.build('rescue-test', {token}, function(err, data) {
if (err){ return console.log(err); }
console.log(data)
});
参考
- https://blog.csdn.net/qq_34832393/article/details/88210942
- https://www.cnblogs.com/hiyong/p/15916702.html
- https://blog.csdn.net/erhaiou2008/article/details/111307873
- https://github.com/jansepar/node-jenkins-api/issues/66
- https://www.npmjs.com/package/node-jenkins-api
- https://github.com/jansepar/node-jenkins-api#readme