# 定义变量
$jarFile = "xxx.jar"
$server = "ip"
$username = "user"
$password = "password"
$remoteHost = "${username}@${server}"
$remoteFolderPath = "path"
$gitDir = "$PSScriptRoot\..\.git"
# 设置环境变量 GIT_DIR
$env:GIT_DIR = $gitDir
git pull
mvn clean package -DskipTests -f $PSScriptRoot/pom.xml -s D:\settings-tianti-mall.xml
# 上传ZIP文件到远程服务器
& pscp -l $username -pw $password "$PSScriptRoot/target/$jarFile" "${remoteHost}:${remoteFolderPath}"
# 执行远程命令
plink.exe -l $username -pw $password $server -batch "cd $remoteFolderPath && bash stop.sh $jarFile && bash start.sh $jarFile"
俺不是很懂,这个是组内一个同事写的脚本,可以执行脚本然后自动上传本地代码,
执行
>powershell
> .\deploy.ps1
执行命令powershell,然后打开powershell,然后执行对应脚本
这是对应的三个脚本
三个脚本内容分别是
remote
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=50055
start.sh
nohup java -jar $1> nohup.out 2>&1 &
stop.sh
rm -rf logs/ nohup.out
ps -ef|grep $1 |grep -v grep|grep -v bash |awk '{print $2}'|xargs kill -9
这个remote是用来本地开启debug,可以本地debug远程服务器代码
bash stop.sh xx.jar
nohup java $(cat remote) -jar xx.jar &