Jenkins和Gitlab通过webhook钩子连接

使用 Jenkins 做自动构建、部署,实现每当提交到 Gitlab 的代码就开始部署工程。关键点就是 Jenkins 和 Gitlab 之间的关联如何打通?如何配置?
解决的方式:Gitlab 中的 Webhooks(钩子)。

## Jenkins job编辑界面:构建触发器 -> Build when a change is pushed to GitLab 
Build when a change is pushed to GitLab. GitLab webhook URL: http://192.168.98.21:8080/jenkins/project/http-demo
此功能需要安装 GitLab 插件
获取地址:http://192.168.98.21:8080/jenkins/project/http-demo

## Gitlab settings/Webhooks 钩子,自动 build
gitlab:project -> settings -> webhooks
URL: http://192.168.98.21:8080/project/http-demo
Add webhook

## 遇到问题 1:url is blocked. requests to the local network are not allowed
git界面:小扳手图标(admin area) -> settings -> network -> Outbound requests, 两个选项勾上

## 遇到问题 2:403 访问不通,也就是 Jenkins 和 GitLab 没有联通
Hook executed successfully but returned HTTP 403 <html> <head> <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/> <title>Error 403 No valid crumb was included in the request</title> </head> <body><h2>HTTP ERROR 403 No valid crumb was included in the request</h2> <table> <tr><th>URI:</th><td>/jenkins/project/http-demo</td></tr> <tr><th>STATUS:</th><td>403</td></tr> <tr><th>MESSAGE:</th><td>No valid crumb was included in the request</td></tr> <tr><th>SERVLET:</th><td>Stapler</td></tr> </table> <hr><a href="http://eclipse.org/jetty">Powered by Jetty:// 9.4.27.v20200227</a><hr/> </body> </html>
解决:(1) jenkins 系统配置 -> 配置 -> GitLab 选项取消勾掉
(2)问题在地址的url后缀,没有 jenkins 路径
复制过来的地址是这样的:http://192.168.98.21:8080/jenkins/project/http-demo
正确是:http://192.168.98.21:8080/project/http-demo

## 测试钩子是否成功
test -> push events
显示下面的 200 就是成功:Hook executed successfully: HTTP 200 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值