通过URL触发Jenkins构建

  • 用Jenkins做持续集成时,一般会使用webhooks触发构建,或者定时构建,这里记录用URL的方式触发Jenkins构建。

1、创建一个用户

登陆Jenking——系统管理——用户管理—— Create User

2、用户添加权限

系统管理——全局安全配置

3、发送CURL POST请求

curl -I -u test:<Userpasswd> -X POST "http://<Jenkins_server:port>/job/<Job_Name>/build?BUILD_TYPE=Update"

test:创建的用户名
<Userpasswd>:用户密码
<Jenkins_server:port>:Jenkins服务器的地址+端口
<Job_Name>:任务名,需要构建那个任务
BUILD_TYPE=Update:可选,构建类型

正常应该为:200 OK 或 201 Created
通过Jenkins页面Build Executor Status查看是否正常构建

如果出现403错误:No valid crumb was included in the request
系统管理 –> Configure Global Security中调整设置:
取消“防止跨站点请求伪造(Prevent Cross Site Request Forgery exploits)”的勾选。

参考链接

猜你喜欢

转载自www.cnblogs.com/zongxiang/p/12015872.html