jenkins+gitlab自动部署代码
###
1、前提
部署 jenkins
安装jenkins插件
Git
Gitlab
Gitlab Hook
Publish Over SSH
SSH Agent
Git Paramete
部署 gitlab
2、jenkins配置免密拉取gitlab代码
配置方法
https://www.cnblogs.com/faithH/p/14949070.html
3、配置jenkins+gitlab(gitlab提交代码后jenkins自动部署)
3.1、gitlab 生成access token
![](https://img2020.cnblogs.com/blog/1274745/202107/1274745-20210701165603063-1409147472.png)
3.2、jenkins 配置允许访问gitlab(添加3.1 生成token完成免密认证)
1、jenkins 添加凭证信息
![](https://img2020.cnblogs.com/blog/1274745/202107/1274745-20210701165858216-226022059.png)
2、jenkins配置免密连接gitlab -- 系统管理 --- 系统配置
![](https://img2020.cnblogs.com/blog/1274745/202107/1274745-20210701170228859-2107856542.png)
3.3、jenkins 任务配置中生成gitlab中webhooks所需webhook url和secret Token
3.4、注意:添加webhoos前必须设置gitlab "Allow requests to local network from hooks and services"权限打开状态,否则添加webhook会报错(gitlab需要admin用户操作)
报错信息:
![](https://img2020.cnblogs.com/blog/1274745/202107/1274745-20210701174037145-1452819375.png)
解决办法;
3.5、gitlab中添加webhooks(gitlab需要admin用户操作)
![](https://img2020.cnblogs.com/blog/1274745/202107/1274745-20210701171947111-561318507.png)
3.6、gitlab上dev分支上创建新文件,jenkins 自动部署
![](https://img2020.cnblogs.com/blog/1274745/202107/1274745-20210705103443047-2028477200.png)
###