分类目录未分类

jenkins_02_备份发布包脚本.sh

#!/bin/bash
# 运行命令 # nohup java -jar ruoyi-admin.jar > ./nohup.out &
# 打包命令 # mvn package -P druid
DATE=`date "+%Y%m%d%H%M%S"`
source /etc/profile
echo “========== 停止包 ruoyi-admin.jar ==========”
PID=`sudo ps -ef |grep "ruoyi-admin.jar" | grep -v grep | awk '{print $2}'`
if [ -z $PID  ]
then
  echo "jar 没有在运行 ...运行新的jar包"
else
  echo "kill $PID"
  sudo kill -9 $PID
fi
#
sleep 6
echo "========== 发布新包 ruoyi-admin.jar =========="

cd /home/jump_guest
mkdir -p /data/jarRun/bak
mv /data/jarRun/ruoyi-admin.jar /data/jarRun/bak/ruoyi-admin.jar.$DATE
mv ruoyi-admin.jar /data/jarRun/ruoyi-admin.jar
chown root.root /data/jarRun/ruoyi-admin.jar
sudo find /data/jarRun/bak/ -type f -mtime +30 -exec rm -f  {} \;

cd /data/jarRun
nohup java -jar ruoyi-admin.jar > ruoyi.log &

jenkins_01_复制备份包脚本.sh

#!/bin/bash
# 运行命令 # nohup java -jar ruoyi-admin.jar > ./nohup.out &
# 打包命令 # mvn package -P druid      jia包会在 target/ruoyi-admin.jar
# jump_guest.pem 私钥 
WORKSPACE="$1"
DATE=`date "+%Y-%m-%d %H:%M:%S"`
Jar='ruoyi-admin.jar'
Dir=/opt/scripts/ssyy99_scripts

echo "当前执行时间为:$DATE"
case $status in
Deploy)
        echo "========= status:$status =========="
        echo "========= 自定义输入version:$version =========="
        echo $PATH
        echo "========= 进入jenkins工作目录前端源码所在文件夹 =========="
        source /etc/profile

        cd $WORKSPACE

########## 用scp命令发动到远程服务器的部署目录下 ##########
        echo "========== 开始上传jar包到测试服务器 =========="
        sudo scp -P 59157 -r -i $Dir/jump_guest.pem $WORKSPACE/ruoyi-admin/target/$Jar jump_guest@192.168.10.1:/home/jump_guest/
        echo "========= 将jar包备份到backup_jar文件夹 =========="

########## 备份在jenkins的工作目录下的backup_app文件夹下,方便之后回滚 ##########
########## $BUILD_NUMBER 为构建id,初始为1 每一次构建递增1 可用于回滚 ##########
########## $WORKSPACE 为项目工作目录 实际为jenkins安装目录+项目名字 ##########
########## $JENKINS_HOME 为jenkins安装目录 在此为 /var/lib/jenkins ##########
        \cp $WORKSPACE/ruoyi-admin/target/$Jar  $JENKINS_HOME/workspace/backup_jar/"$Jar".$BUILD_NUMBER
        sudo find $JENKINS_HOME/workspace/backup_jar/ -type f -mtime +30 -exec rm -f  {} \;

    echo "deploy done!"
    ;;

Rollback)
        backup_path="${JENKINS_HOME}/workspace/backup_jar/"
        echo "======status:$status========"
        echo "======build_id:$version======="
        cd $backup_path
        ls
        echo "==============正在回滚 $Jar.$version 包 发送到远程测试服务器==================="
        sudo scp -P 59157 -r -i $Dir/jump_guest.pem "$Jar".$version  jump_guest@192.168.10.1:/home/jump_guest/$Jar

    echo "roll_back done!"
    ;;
*)
esac