标签:monit bsp dep script ash html space 插件 src
1.脚本
[root@nginx script]# cat autoci.sh #!/bin/bash # 环境变量 # $WORKSPACE:JENKINS自带环境变量,在哪个任务下执行,WORKSAPCE就是哪个目录 # $tag_version:JENKINS任务里面git插件传过来的值,就是程序的tag版本 DATE=`date +%F-%H-%M-%S` FILENAME="monitor-${tag_version}" SDIR=$WORKSPACE DDIR=/usr/local/nginx/html OTHERIP="192.168.3.156 192.168.3.157" #打包程序 archive_code(){ cd $SDIR && tar zcf /script/${FILENAME}.tar.gz ./ } #推送部署程序 deploy_code(){ for IP in $OTHERIP do echo "正在传输文件到$IP" scp -rq /script/${FILENAME}.tar.gz root@$IP:/tmp/ echo "$IP文件传输完成,正在部署" ssh root@$IP "mkdir $DDIR/$FILENAME && tar xf /tmp/${FILENAME}.tar.gz -C $DDIR/$FILENAME && rm -rf $DDIR/monitor && ln -s $DDIR/$FILENAME $DDIR/monitor && /usr/local/nginx/sbin/nginx -s reload" echo "$IP部署完成" done } #部署 deploy(){ archive_code deploy_code } #回滚 back(){ BACKFILE=$(ssh root@192.168.3.156 "find /usr/local/nginx/html/ -maxdepth 1 -name monitor-${tag_version}") if [[ $BACKFILE == "" ]];then echo "无法取到${tag_version}版本,请检查是否已经部署" exit 1 fi for IP in $OTHERIP do echo "正在回滚$IP到$tag_version版本" ssh root@$IP "rm -rf $DDIR/monitor && ln -s $BACKFILE $DDIR/monitor && /usr/local/nginx/sbin/nginx -s reload" echo "$IP回滚完成" done } if [[ $SELECT == "DEPLOY" ]];then deploy elif [[ $SELECT == "BACK" ]];then back fi
2.jenkins页面
3.程序目录,一个tag版本只生成一个程序包
标签:monit bsp dep script ash html space 插件 src
原文地址:https://www.cnblogs.com/forlive/p/12850831.html