自动化脚本部署服务

自动化脚本部署

利用WinSCP.exe和pink.exe程序加bat脚本实现自动化脚本部署服务,自动跟新代码,打包并上传到服务器,重启服务。pink.exe是putty下的一个文件

  • deploy.bat
@echo off
rem 当前目录
set current_dir=%CD%
rem ssh的ip
set ssh_ip=xx.xx.xx.xx
rem ssh的账号
set ssh_user=xx
rem ssh的密码
set ssh_pwd=xx
rem git更新目录
set git_update_dir=xx
rem gradle clean目录
set gradle_clean_dir=xx
rem gradle bootRepackage目录
set gradle_bootRepackage_dir=xx
rem 打包后jar包目录
set resource_dir1=xx
set resource_dir2=xx
set resource_dir3=xx
set resource_dir4=xx
rem 拷贝目录
set target_dir1=xx
set target_dir4=xx
set target_dir3=xx
set target_dir2=xx
rem winscp目录
set winscp_dir=xx
cd /d %git_update_dir%
call git pull || goto gitfailed
echo "code update successful"
cd /d %gradle_clean_dir%
call gradle clean || goto cleanfailed
echo "project clean successful"
cd /d %gradle_bootRepackage_dir%
call gradle bootRepackage || goto gradlefailed
echo "project build successful"
copy /y %resource_dir1%  %target_dir1%
copy /y %resource_dir2%  %target_dir2%
copy /y %resource_dir3%  %target_dir3%
copy /y %resource_dir4%  %target_dir4%
%winscp_dir%\WinSCP.com /script=%current_dir%\upload.bat
echo "upload jar file successful"
echo .|%current_dir%\plink -ssh -l %ssh_user% -pw %ssh_pwd% %ssh_ip% -m %current_dir%\deploy.sh
echo "server service reload successful"
pause
exit
:gitfailed
echo "code update fail"
pause
exit
:cleanfailed
echo "gradle clean fail"
pause
exit
:gradlefailed
echo "gradle build fail"
pause
exit

  • upload.bat
option confirm off
open username:pwd@ip:port
put 本地jar目录 服务jar目录
close
exit
pause
  • deploy.sh
#!/bin/bash
#服务器上的执行脚本
java -jar xx.jar

你可能感兴趣的:(自动化脚本部署服务)