echo "ssh 连接进行备份操作" ssh -Tq -oStrictHostKeyChecking=no user1@${server_ip} <<EOF mkdir -p $DIR/backup/${projectName} mkdir -p $DIR/${projectName} if [ -f "$DIR/${projectName}/${projectName}.jar" ];then mv $DIR/${projectName}/${projectName}.jar $DIR/backup/${projectName}/${projectName}-`date "+%Y%m%d_%H%M%S"`.jar fi EOF echo "拷贝 jar 包到目标服务器的 tmp 目录" scp -q -oStrictHostKeyChecking=no ${WORKSPACE}/target/*.jar use1@${server_ip}:/xxx/xxx/${projectName}.jar echo "ssh 远程连接进行发布操作" ssh -q -oStrictHostKeyChecking=no user1@${server_ip} <<EOF mv /xxx/xxx/${projectName}.jar $DIR/${projectName}/${projectName}.jar echo "copy jar success" echo "开始部署远程服务器" echo "先停止服务${projectName}" sh $DIR/${projectName}/stop.sh echo "启动服务${projectName}" sh $DIR/${projectName}/start.sh EOF done echo "success"