前言
实现自动部署
开发人员上传代码到gitlab
gitlab-runner 检测到操作便开始自动部署
部署检测代码的是java还是web,检测需要部署的端口,实现根据代码和端口部署
部署完成发送信息到企业微信
分析实现步骤
安装gitlab-runner
在需要部署java程序的机器上绑定 ,tags为test部署java程序
在需要部署web程序的机器上绑定 ,tags为test部署web程序
编写.gitlab-ci.yml放在项目的第一级目录
编写shell脚本实现部署
实现企业微信报警
检测是否自动部署
安装gitlab
部署gitlab-runner
使用gitlab-runner实现自动部署
# 安装repository
curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.rpm.sh | sudo bash
# 安装gitlab-runner
yum install gitlab-runner
在需要部署的机器上注册
url以及token获取
url以及token位置
[root@test2 SHELL]# gitlab-runner register
Runtime platform arch=amd64 os=linux pid=53435 revision=d0b76032 version=12.0.2
Running in system-mode.
Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/):
http://192.168.0.71/gitlab/ #输入URL
Please enter the gitlab-ci token for this runner:
-rwbBw2y7GmL7smxuoxt #输入TOKEN
Please enter the gitlab-ci description for this runner:
[test2.laozios.com]: test #后面脚本需要用到
Please enter the gitlab-ci tags for this runner (comma separated):
test #后面脚本需要用到
Registering runner... succeeded runner=-rwbBw2y
Please enter the executor: parallels, kubernetes, virtualbox, docker+machine, docker-ssh+machine, docker, docker-ssh, shell, ssh:
shell #通过shell
Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!
执行过程
查看结果
命令行查看
gitlab-runner list
查看是否绑定成功
gitlab页面查看
查看结果
重复上面步骤
刚刚绑定的是test应该为对于的【java】【web】
编写.gitlab-ci.yml文件
stages:
- deploy