天天看点

创建Jenkins构建触发器,代码提交至gitLab即自动触发构建

下载所需插件,系统设置--》插件管理,搜索以下两个插件,选择安装

创建Jenkins构建触发器,代码提交至gitLab即自动触发构建

登录gitLab,生成一个Personal Access Tokens

创建Jenkins构建触发器,代码提交至gitLab即自动触发构建
创建Jenkins构建触发器,代码提交至gitLab即自动触发构建
创建Jenkins构建触发器,代码提交至gitLab即自动触发构建

 进入Jenkins,添加api token,路径:首页--》凭据--》添加凭据

创建Jenkins构建触发器,代码提交至gitLab即自动触发构建

添加后再次打开,如图所示

创建Jenkins构建触发器,代码提交至gitLab即自动触发构建

 然后打开系统管理,进入系统设置,配置gitLab

创建Jenkins构建触发器,代码提交至gitLab即自动触发构建

然后进入job,进行配置

创建Jenkins构建触发器,代码提交至gitLab即自动触发构建
创建Jenkins构建触发器,代码提交至gitLab即自动触发构建

进入GitLab,打开项目--》settings

创建Jenkins构建触发器,代码提交至gitLab即自动触发构建
创建Jenkins构建触发器,代码提交至gitLab即自动触发构建
创建Jenkins构建触发器,代码提交至gitLab即自动触发构建

测试成功,返回200

创建Jenkins构建触发器,代码提交至gitLab即自动触发构建

到此,触发器配置成功,开发一旦有提交代码,就会自动构建,如图所示

创建Jenkins构建触发器,代码提交至gitLab即自动触发构建

 Ps:遇到的问题:gitLab上添加webhook保存,报错Requests to localhost are not allowed

解决方案:需要使用管理员帐号登录,进入Admin area,在Admin area中,在settings标签下面,找到OutBound Request,勾选上Allow requests to the local network from hooks and services ,保存更改即可解决问题

创建Jenkins构建触发器,代码提交至gitLab即自动触发构建