jenkins 回退发布脚本

case $Status in
Deploy)
echo "Status:$Status"
path="${JENKINS_HOME}/workspace/bak/${JOB_NAME}/${BUILD_NUMBER}" #创建每次要备份的目录
if [ -d $path ];
then
echo "The files is already exists "
else
mkdir -p $path
fi
\cp -rf ${WORKSPACE} $path #将打包好的war包备份到相应目录,覆盖已存在的目标
echo "Completing!"
;;
Rollback)
echo "Status:$Status"
echo "Version:$Version"
rm -rf ${JENKINS_HOME}/workspace/${JOB_NAME}_new
mkdir -p ${JENKINS_HOME}/workspace/${JOB_NAME}_new
cd ${JENKINS_HOME}/workspace/bak/${JOB_NAME}/$Version/${JOB_NAME} #进入备份目录
\cp -rf ./ ${JENKINS_HOME}/workspace/${JOB_NAME}_new #将备份拷贝到程序打包目录中,并覆盖之前的war包
mv ${JENKINS_HOME}/workspace/${JOB_NAME} ${JENKINS_HOME}/workspace/${JOB_NAME}_old
mv ${JENKINS_HOME}/workspace/${JOB_NAME}_new ${JENKINS_HOME}/workspace/${JOB_NAME}
rm -rf ${JENKINS_HOME}/workspace/${JOB_NAME}_old
rm -rf ${JENKINS_HOME}/workspace/${JOB_NAME}_new
;;
*)
exit
;;
esac