[root@jenkins scripts]# cat java_deploy_tag_rollback.sh #!/bin/bash DATE=$(date +%Y-%m-%d-%H-%M-%S) web_server="192.168.220.143 192.168.220.144" Sdir=/opt Ddir=/apps/tomcat/webapps Tomcat_Home=/apps/tomcat Name=${DATE}-${git_version} # 1 进入项目目录,将内容进行打包 get_code(){ #cd /var/lib/jenkins/workspace/freestyle-monitor && \ echo ${WORKSPACE} cd ${WORKSPACE} } # 2 将内容通过scp拷贝至web集群组 scp_web_server(){ for host in $web_server do scp target/*.war root@$host:/opt/ROOT-${DATE}-${git_version}.war ssh root@$host "mkdir -p ${Ddir}/ROOT-${DATE}-${git_version} && \ unzip /opt/ROOT-${DATE}-${git_version}.war -d ${Ddir}/ROOT-${DATE}-${git_version} && \ rm -rf ${Ddir}/ROOT && \ ln -s ${Ddir}/ROOT-${DATE}-${git_version} ${Ddir}/ROOT && \ ${Tomcat_Home}/bin/shutdown.sh && ${Tomcat_Home}/bin/startup.sh" done } deploy(){ get_code scp_web_server } rollback(){ echo "开始准备回退..." for host in $web_server do back_file=$(ssh root@$host "find ${Ddir}/ -maxdepth 1 -type d -name "\\*-${git_version}"") # back_file=$(ssh root@$host "find ${Ddir} -maxdepth 1 -type d -name "${git_version}"") echo -e "back_file= ${back_file}" ssh root@$host " rm -rf ${Ddir}/ROOT && \ ln -s ${back_file} ${Ddir}/ROOT && \ ${Tomcat_Home}/bin/shutdown.sh && ${Tomcat_Home}/bin/startup.sh" done } echo `whoami` if [ $deploy_env == 'deploy' ];then if [ ${GIT_COMMIT} == ${GIT_PREVIOUS_SUCCESSFUL_COMMIT} ];then echo "您已经部署过该${git_version}版本" exit 1 else deploy fi elif [ $deploy_env == 'rollback' ];then rollback fi
Jenkins java服务更新和回滚
标签:回滚,git,java,Ddir,host,version,&&,Jenkins,ROOT From: https://www.cnblogs.com/zhouzhiguo/p/16832339.html