本文最后更新于 952 天前,其中的信息可能已经有所发展或是发生改变。
GitLab构建SSH
ssh-keygen -t rsa -C "admin@example.com"
ls ~/.ssh
# id_rsa 私钥 id_rsa.pub 公钥
Edit profile -> SSH Keys
CI持续集成
远程拉取代码
- Jenkins服务器安装Git
yum install -y git - Jenkins安装GitLab插件,Manage Jenkins -> Manage Plugins -> Available -> GitLab -> Install without restart
- 创建空项目,New Item -> Freestyle project(springboot-demo)
- 连接GitLab
- 生成SSH密钥
git ssh-keygen -t rsa -C "admin@example.com" ls ~/.ssh # id_rsa 私钥 id_rsa.pub 公钥 - Jenkins设置代码路径,springboot-demo -> Configure -> Source Code Management -> Git -> Repository URL(http://192.168.153.52:8929/root/springboot-demo.git) -> Credentials(add) -> SSH Username with private key(Username:root,Private Key:id_rsa)
- 运行项目,springboot-demo -> Build Now
Webhook钩子
- 设置令牌,生成24位随机数
head -c 16 /dev/urandom | base64
# 0KMRH8mxGrms82ygJcXhlw==
- Jenkins设置身份令牌,springboot-demo -> Configure -> Build Triggers -> Trigger builds remotely (Authentication Token:0KMRH8mxGrms82ygJcXhlw==)
- 同时勾选 Build when a change is pushed to GitLab. GitLab webhook URL: http://192.168.153.51:8080/project/springboot-demo
- 开启匿名用户可读权限,Manage Jenkins -> Configure Global Security -> Logged-in users can do anything -> Allow anonymous read access
- 关闭”/project”端点身份验证,Manage Jenkins -> System Configuration -> Gitlab -> 去掉勾选(Enable authentication for ‘/project’ end-point)
- GitLab设置允许Webhook,Menu -> Admin -> Settings -> Network -> Outbound requests -> Allow requests to the local network from web hooks and services
- 设置Webhook,springboot-demo -> Settings -> Webhooks(URL:http://192.168.153.51:8080/project/springboot-demo,Secret token:0KMRH8mxGrms82ygJcXhlw==)
