利用Gitlab的webhook实现代码push到仓库,立即触发项目自动构建。
1. 安装Gitlab Hook插件
需要安装两个插件:Gitlab Hook和GitLab
2. Jenkins设置自动构建
新建Item
点击确定
在构建触发器选择如下设置
复制地址,备用
http://192.168.2.3:8888/project/test03_pipeline_gitlab
在流水线出配置读取项目中的pipeline脚本
点击应用,保存
3. 在Jenkins中开启允许gitlab访问
Manage Jenkins->Configure System
此处取消勾选,点击应用保存
4. Gitlab配置webhook
1. 开启webhook功能
使用root账户登录到后台,点击Admin Area -> Settings -> Network
勾选"Allow requests to the local network from web hooks and services"
点击save change
2. 在当前gitlab项目添加webhook
首先进入当前项目主页->Settings->Integrations
填入之前在jenkins创建项目,构建触发器时获取到的URL地址
3. 测试push
点击Test,看能否触发执行Jenkins
此时已经成功触发