安装参考 部署jar到远程服务器 - SSH.md 👉 远程服务器安装agentInstaller.exe

create project

http://localhost:8111/admin/admin.html?item=projects

image.png image.png image.png

Build Step

image.png

maven 打包之前先停止项目(windows powershell

  1. echo "======view 9001 point======";
  2. $points=(netstat -ano | findstr 9001);
  3. echo $points;
  4. if($points.gettype().Name -eq "Object[]"){
  5. $points=$points.get(0);
  6. }
  7. echo "======kill 9001 point======";
  8. $pids=-Split $points;
  9. if($pids.length -gt 0) {
  10. taskkill /t /f /im $pids[$pids.length-1];
  11. echo "======kill success======";
  12. }

image.png

maven 打包

clean package -DskipTests -Dmaven.javadoc.skip=true

image.png

powershell

  1. powershell 调用 bat脚本

    推荐

  1. cd %teamcity.build.workingDir%\src\main\resources\script\bat
  2. start .\start-stop-teamcity.bat %teamcity.build.workingDir%\target
  1. CHCP 65001
  2. @echo off
  3. @echo 先关闭进程
  4. title cqepc
  5. color 0c
  6. rem 设置监听的端口号
  7. set port=9001
  8. rem 尽量写全路径
  9. set jarName=cqepc-0.0.1-SNAPSHOT.jar
  10. echo port : %port%
  11. set PROJECT_PROPERTIES=prod
  12. rem -XX:+UseConcMarkSweepGC -XX:+UseParNewGC || -XX:+UseParallelGC -XX:+UseParallelOldGC
  13. set JAVA_OPTS= -Xms1024m
  14. set JAVA_OPTS= %JAVA_OPTS% -Xmx1024m -Xmn512m -XX:+UseParallelGC -XX:+UseParallelOldGC
  15. set JAVA_OPTS= %JAVA_OPTS% -Dfile.encoding=utf-8
  16. set SERVER_PORT= --server.port=%port%
  17. set SERVER_PROPERTIES= --spring.profiles.active=%PROJECT_PROPERTIES%
  18. for /f "usebackq tokens=1-5" %%a in (`netstat -ano ^| findstr %port%`) do (
  19. if [%%d] EQU [LISTENING] (
  20. set pid=%%e
  21. )
  22. )
  23. for /f "usebackq tokens=1-5" %%a in (`tasklist ^| findstr %pid%`) do (
  24. set image_name=%%a
  25. )
  26. echo now will kill process : pid %pid%, image_name %image_name%
  27. rem 根据进程IDkill进程
  28. taskkill /f /pid %pid%
  29. @echo %pid%的进程停止成功
  30. @echo 启动%jarName%
  31. rem %1 运行bat时传入的值
  32. set curdir=%1
  33. cd /d %curdir%
  34. echo %curdir%
  35. java %JAVA_OPTS% -jar %jarName% %SERVER_PORT% %SERVER_PROPERTIES%
  36. pause

image.png

  1. powershell 直接使用命令script code source
    1. 这样或让线程一直等待,因为windows中没有后台运行的命令
    2. image.png
    3. image.png
  1. echo "======view 9001 point======";
  2. $points=(netstat -ano | findstr 9001);
  3. echo $points;
  4. if($points.gettype().Name -eq "Object[]"){
  5. $points=$po ints.get(0);
  6. }
  7. echo "======kill 9001 point======";
  8. $pids=-Split $points;
  9. if($pids.length -gt 0) {
  10. taskkill /t /f /im $pids[$pids.length-1];
  11. echo "======kill success======";
  12. }
  13. cd /d %teamcity.build.workingDir%\target
  14. java -jar .\cqepc-0.0.1-SNAPSHOT.jar --spring.profiles.active=prod

选择服务

Agents > Pools (3) — TeamCity 将需要部署的服务放到指定服务器中 image.pngimage.png