ci自动化构建java项目_gitlab+gitlab-runner搭建自动化部署

本文介绍了如何通过gitlab和gitlab-runner实现Java项目的CI自动化部署,包括设置gitlab-runner、编写.gitlab-ci.yml文件、环境判断及部署脚本,以及部署完成后的企业微信通知。此外,还提到了gitlab-runner的工作路径和执行用户配置。
摘要由CSDN通过智能技术生成

前言

实现自动部署

开发人员上传代码到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获取

1014b0ec876d?utm_campaign=haruki&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

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!

1014b0ec876d?utm_campaign=haruki&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

执行过程

查看结果

命令行查看

gitlab-runner list

1014b0ec876d?utm_campaign=haruki&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

查看是否绑定成功

gitlab页面查看

1014b0ec876d?utm_campaign=haruki&utm_content=note&utm_medium=seo_notes&utm_source=recommendation

查看结果

重复上面步骤

刚刚绑定的是test应该为对于的【java】【web】

编写.gitlab-ci.yml文件

stages:

- deploy

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值