jenkins自动化部署springboot
一、linux按jar包名称部署
1.执行shell
PID=$(ps -ef | grep app.jar | grep -v grep | awk '{ print $2 }') if [ -z "$PID" ] then echo Application is already stopped else echo kill $PID kill $PID fi
2.调用顶层maven目标
clean package -Dmaven.test.skip=true
3.执行shell
cd target BUILD_ID=dontKillMe nohup java -jar app.jar &
二、linux按端口部署
1.执行shell
PID=$(lsof -i:端口号 |awk '{print $2}' | tail -n 1) if [ -z "$PID" ] then echo Application is already stopped else echo kill $PID kill $PID fi
2.调用顶层maven目标
clean package -Dmaven.test.skip=true
3.执行shell
cd target BUILD_ID=dontKillMe nohup java -Dspring.profiles.active=dev -jar app.jar &
三、windows 通过端口发布
1.执行windows批处理命令
@echo off set port=8081 for /f "tokens=1-5" %%i in ('netstat -ano^|findstr ":%port%"') do ( taskkill /pid %%m /f exit /b )
2.执行windows批处理命令
if not exist "E:\appdir" md "E:\appdir" copy .\target\app.jar E:\appdir\app.jar
3.执行widnows批处理命令
@echo off cd E:\appdir\ E: start javaw -Dserver.port=8081 -jar -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=128m -Xms1024m -Xmx1024m -Xmn256m -Xss256k app.jar exit