安装参考 部署jar到远程服务器 - SSH.md 👉 远程服务器安装agentInstaller.exe
create project
http://localhost:8111/admin/admin.html?item=projects
Build Step
maven 打包之前先停止项目(windows powershell
echo "======view 9001 point======";
$points=(netstat -ano | findstr 9001);
echo $points;
if($points.gettype().Name -eq "Object[]"){
$points=$points.get(0);
}
echo "======kill 9001 point======";
$pids=-Split $points;
if($pids.length -gt 0) {
taskkill /t /f /im $pids[$pids.length-1];
echo "======kill success======";
}
maven 打包
clean package -DskipTests -Dmaven.javadoc.skip=true
powershell
- powershell 调用 bat脚本
推荐
cd %teamcity.build.workingDir%\src\main\resources\script\bat
start .\start-stop-teamcity.bat %teamcity.build.workingDir%\target
CHCP 65001
@echo off
@echo 先关闭进程
title cqepc
color 0c
rem 设置监听的端口号
set port=9001
rem 尽量写全路径
set jarName=cqepc-0.0.1-SNAPSHOT.jar
echo port : %port%
set PROJECT_PROPERTIES=prod
rem -XX:+UseConcMarkSweepGC -XX:+UseParNewGC || -XX:+UseParallelGC -XX:+UseParallelOldGC
set JAVA_OPTS= -Xms1024m
set JAVA_OPTS= %JAVA_OPTS% -Xmx1024m -Xmn512m -XX:+UseParallelGC -XX:+UseParallelOldGC
set JAVA_OPTS= %JAVA_OPTS% -Dfile.encoding=utf-8
set SERVER_PORT= --server.port=%port%
set SERVER_PROPERTIES= --spring.profiles.active=%PROJECT_PROPERTIES%
for /f "usebackq tokens=1-5" %%a in (`netstat -ano ^| findstr %port%`) do (
if [%%d] EQU [LISTENING] (
set pid=%%e
)
)
for /f "usebackq tokens=1-5" %%a in (`tasklist ^| findstr %pid%`) do (
set image_name=%%a
)
echo now will kill process : pid %pid%, image_name %image_name%
rem 根据进程ID,kill进程
taskkill /f /pid %pid%
@echo %pid%的进程停止成功
@echo 启动%jarName%
rem %1 运行bat时传入的值
set curdir=%1
cd /d %curdir%
echo %curdir%
java %JAVA_OPTS% -jar %jarName% %SERVER_PORT% %SERVER_PROPERTIES%
pause
- powershell 直接使用命令script code source
- 这样或让线程一直等待,因为windows中没有后台运行的命令
echo "======view 9001 point======";
$points=(netstat -ano | findstr 9001);
echo $points;
if($points.gettype().Name -eq "Object[]"){
$points=$po ints.get(0);
}
echo "======kill 9001 point======";
$pids=-Split $points;
if($pids.length -gt 0) {
taskkill /t /f /im $pids[$pids.length-1];
echo "======kill success======";
}
cd /d %teamcity.build.workingDir%\target
java -jar .\cqepc-0.0.1-SNAPSHOT.jar --spring.profiles.active=prod
选择服务
Agents > Pools (3) — TeamCity 将需要部署的服务放到指定服务器中