Gitlab-CI持续集成spring-boot项目

为实现持续集成,需为该项目准备以下两样东西:

  1. 软件集成脚本 .gitlab-ci.yml 放在项目根目录即可
  2. 一台Runner服务器【gitlab所在服务器即可,或者可以单独开一台】

安装Runner

Centos使用yum安装

cat << EOF >> /etc/yum.repos.d/gitlab-ci-multirunner.repo
[gitlab-ci-multi-runner]
name=gitlab-ci-multi-runner
baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ci-multi-runner/yum/el7
repo_gpgcheck=0
gpgcheck=0
enabled=1
gpgkey=https://packages.gitlab.com/gpg.key
EOF
sudo yum makecache
# 注意和gitlab配套 我用的是 GitLab中文社区版 8.8.5 用这个老版本
sudo yum install gitlab-ci-multi-runner-1.11.2-1

注册Runner

gitlab-runner register

##在 .gitlab-ci.yml编写shell

#build过程
build:
  stage: build
  script:
    - /home/apache-maven-3.6.3/bin/mvn clean package -DskipTests=true
    - cp ./target/approval.jar /home/approval.jar
#分支
  only:
    - master
#发布过程
deploy:
  stage: deploy
  script:
    - bash bin/restart.sh approval
  dependencies:
    - build
# restart.sh
#!/bin/bash
if [ $# -ne 1 ]
then
        echo "arguments error!"
        exit 1
else
        jarname=$1
        echo $jarname
        pid=`ps -ef | grep "$jarname.jar"|grep -v grep|awk '{print $2}'`
        for id in $pid
        do
                echo $id
                kill -9 $id
                echo "killed $id"
        done
        nohup java -jar /home/$jarname.jar > /home/$jarname-log.log 2>&1 &
fi

##设置触发条件
默认每次push都会自动集成

参考地址

😃 https://blog.csdn.net/wbf810207/article/details/90412358

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值