Jenkins+GitLab 持续集成
本文最后更新于 952 天前,其中的信息可能已经有所发展或是发生改变。

GitLab构建SSH

ssh-keygen -t rsa -C "admin@example.com"
ls ~/.ssh
# id_rsa 私钥 id_rsa.pub 公钥

Edit profile -> SSH Keys

CI持续集成

远程拉取代码

  1. Jenkins服务器安装Gityum install -y git
  2. Jenkins安装GitLab插件,Manage Jenkins -> Manage Plugins -> Available -> GitLab -> Install without restart
  3. 创建空项目,New Item -> Freestyle project(springboot-demo)
  4. 连接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)
  1. 运行项目,springboot-demo -> Build Now

Webhook钩子

  1. 设置令牌,生成24位随机数
   head -c 16 /dev/urandom | base64
   # 0KMRH8mxGrms82ygJcXhlw==
  1. Jenkins设置身份令牌,springboot-demo -> Configure -> Build Triggers -> Trigger builds remotely (Authentication Token:0KMRH8mxGrms82ygJcXhlw==)
  2. 同时勾选 Build when a change is pushed to GitLab. GitLab webhook URL: http://192.168.153.51:8080/project/springboot-demo
  3. 开启匿名用户可读权限,Manage Jenkins -> Configure Global Security -> Logged-in users can do anything -> Allow anonymous read access
  4. 关闭”/project”端点身份验证,Manage Jenkins -> System Configuration -> Gitlab -> 去掉勾选(Enable authentication for ‘/project’ end-point)
  5. GitLab设置允许Webhook,Menu -> Admin -> Settings -> Network -> Outbound requests -> Allow requests to the local network from web hooks and services
  6. 设置Webhook,springboot-demo -> Settings -> Webhooks(URL:http://192.168.153.51:8080/project/springboot-demo,Secret token:0KMRH8mxGrms82ygJcXhlw==)
如果觉得本文对您有帮助,记得收藏哦~
上一篇
下一篇