1.新建Item
-
主页选择 -> 新建Item
-
输入任务名称,选择 -> 构建一个maven项目
2.添加项目描述
3.源码管理(git)
4.构建触发器
5.构建环境
根据自己需求选择
6.Pre Steps
添加Windows batch command命令,构建前杀掉对应的进程,例如demo-1.0.2.jar所对应的进程
-
@echo off
-
for /f "tokens=1,2 delims=" %%a in ('jps') do (if "%%b"=="demo-1.0.1.jar" (set pid=%%a))
-
if DEFINED pid taskkill /pid %pid% /f
7.Build(构建)
8.Pre Steps
添加Windows batch command命令,后台运行编译好的jar,-Dfile.encoding指定编码格式
-
@echo off
-
xcopy D:\jenkins\workspace\demo\target\demo-1.0.1.jar D:\demo\ /Y
-
start javaw -jar -Dfile.encoding=utf-8 D:\demo\demo-1.0.1.jar &
-
echo - - - - - - - - - - - - - - - - - demo.jar 启动成功! - - - - - - - - - - - - - - - - -
-
exit
9.构建后操作
根据自己需求选择,例如发送邮件等
10.添加环境变量,否则构建完成后自动杀掉jar
- 系统管理(Manage Jenkins)–> 管理节点(Manage Nodes and Clouds)
- 找到发包节点(master),点击设置
- 点击Environment variables,增加环境变量,保存后执行构建
批量脚本 Pre:
@echo off for /f "tokens=1,2 delims= " %%a in ('jps') do ( if "%%b"=="ybtcloud-coplt-service-1.0-SNAPSHOT.jar" ( set pid=%%a echo %%a ) ) if DEFINED pid ( taskkill /pid %pid% /f ) echo - - - - - - - - - - - - - - - - - ybtcloud-coplt-service-1.0-SNAPSHOT.jar 停止成功! - - - - - - - - - - - - - - - - - for /f "tokens=1,2 delims= " %%a in ('jps') do ( if "%%b"=="ybtcloud-ecologev-service-1.0-SNAPSHOT.jar" ( set pid=%%a echo %%a ) ) if DEFINED pid ( taskkill /pid %pid% /f ) echo - - - - - - - - - - - - - - - - - ybtcloud-ecologev-service-1.0-SNAPSHOT.jar 停止成功! - - - - - - - - - - - - - - - - - for /f "tokens=1,2 delims= " %%a in ('jps') do ( if "%%b"=="ybtcloud-file-service-1.0-SNAPSHOT.jar" ( set pid=%%a echo %%a ) ) if DEFINED pid ( taskkill /pid %pid% /f ) echo - - - - - - - - - - - - - - - - - ybtcloud-file-service-1.0-SNAPSHOT.jar 停止成功! - - - - - - - - - - - - - - - - - for /f "tokens=1,2 delims= " %%a in ('jps') do ( if "%%b"=="ybtcloud-form-service-1.0-SNAPSHOT.jar" ( set pid=%%a echo %%a ) ) if DEFINED pid ( taskkill /pid %pid% /f ) echo - - - - - - - - - - - - - - - - - ybtcloud-form-service-1.0-SNAPSHOT.jar 停止成功! - - - - - - - - - - - - - - - - - for /f "tokens=1,2 delims= " %%a in ('jps') do ( if "%%b"=="imq-admin.jar" ( set pid=%%a echo %%a ) ) if DEFINED pid ( taskkill /pid %pid% /f ) echo - - - - - - - - - - - - - - - - - imq-admin.jar 停止成功! - - - - - - - - - - - - - - - - - for /f "tokens=1,2 delims= " %%a in ('jps') do ( if "%%b"=="ybtcloud-ncqc-service-1.0-SNAPSHOT.jar" ( set pid=%%a echo %%a ) ) if DEFINED pid ( taskkill /pid %pid% /f ) echo - - - - - - - - - - - - - - - - - ybtcloud-ncqc-service-1.0-SNAPSHOT.jar 停止成功! - - - - - - - - - - - - - - - - - for /f "tokens=1,2 delims= " %%a in ('jps') do ( if "%%b"=="ybtcloud-plt-service-1.0-SNAPSHOT.jar" ( set pid=%%a echo %%a ) ) if DEFINED pid ( taskkill /pid %pid% /f ) echo - - - - - - - - - - - - - - - - - ybtcloud-plt-service-1.0-SNAPSHOT.jar 停止成功! - - - - - - - - - - - - - - - - - for /f "tokens=1,2 delims= " %%a in ('jps') do ( if "%%b"=="ybtcloud-pve-service-1.0-SNAPSHOT.jar" ( set pid=%%a echo %%a ) ) if DEFINED pid ( taskkill /pid %pid% /f ) echo - - - - - - - - - - - - - - - - - ybtcloud-pve-service-1.0-SNAPSHOT.jar 停止成功! - - - - - - - - - - - - - - - - - for /f "tokens=1,2 delims= " %%a in ('jps') do ( if "%%b"=="ybtcloud-qcp-service-1.0-SNAPSHOT.jar" ( set pid=%%a echo %%a ) ) if DEFINED pid ( taskkill /pid %pid% /f ) echo - - - - - - - - - - - - - - - - - ybtcloud-qcp-service-1.0-SNAPSHOT.jar 停止成功! - - - - - - - - - - - - - - - - - for /f "tokens=1,2 delims= " %%a in ('jps') do ( if "%%b"=="ybtcloud-qcs-service-1.0-SNAPSHOT.jar" ( set pid=%%a echo %%a ) ) if DEFINED pid ( taskkill /pid %pid% /f ) echo - - - - - - - - - - - - - - - - - ybtcloud-qcs-service-1.0-SNAPSHOT.jar 停止成功! - - - - - - - - - - - - - - - - - for /f "tokens=1,2 delims= " %%a in ('jps') do ( if "%%b"=="ybtcloud-qcs-service-1.0-SNAPSHOT.jar" ( set pid=%%a echo %%a ) ) if DEFINED pid ( taskkill /pid %pid% /f ) echo - - - - - - - - - - - - - - - - - ybtcloud-qcs-service-1.0-SNAPSHOT.jar 停止成功! - - - - - - - - - - - - - - - - - for /f "tokens=1,2 delims= " %%a in ('jps') do ( if "%%b"=="ybtcloud-teo-service-1.0-SNAPSHOT.jar" ( set pid=%%a echo %%a ) ) if DEFINED pid ( taskkill /pid %pid% /f ) echo - - - - - - - - - - - - - - - - - ybtcloud-teo-service-1.0-SNAPSHOT.jar 停止成功! - - - - - - - - - - - - - - - - -
批量脚本 Post:
set BUILD_ID=dontKillMe
set JENKINS_NODE_COOKIE=dontKillMe
@echo off
echo ybtcloud-coplt-service-1.0-SNAPSHOT.jar
xcopy D:\ProgramFiles\Jenkins\workspace\Jenkins\.jenkins\workspace\ybtcloud\ybtcloud-coplt\ybtcloud-coplt-service\target\ybtcloud-coplt-service-1.0-SNAPSHOT.jar D:\ybtcloud\ybtcloud-coplt\ /Y
cd D:\ybtcloud\ybtcloud-coplt\
start C:\ProgramFiles\Java\jdk1.8.0_181\bin\javaw -Xms256m -Xmx512m -Dspring.profiles.active=prod -jar ybtcloud-coplt-service-1.0-SNAPSHOT.jar &
echo - - - - - - - - - - - - - - - - - ybtcloud-coplt-service-1.0-SNAPSHOT.jar 启动成功! - - - - - - - - - - - - - - - - -
echo ybtcloud-ecologev-service-1.0-SNAPSHOT.jar
xcopy D:\ProgramFiles\Jenkins\workspace\Jenkins\.jenkins\workspace\ybtcloud\ybtcloud-ecologev\ybtcloud-ecologev-service\target\ybtcloud-ecologev-service-1.0-SNAPSHOT.jar D:\ybtcloud\ybtcloud-ecologev\ /Y
cd D:\ybtcloud\ybtcloud-ecologev\
start C:\ProgramFiles\Java\jdk1.8.0_181\bin\javaw -Xms256m -Xmx512m -Dspring.profiles.active=prod -jar ybtcloud-ecologev-service-1.0-SNAPSHOT.jar &
echo - - - - - - - - - - - - - - - - - ybtcloud-coplt-service-1.0-SNAPSHOT.jar 启动成功! - - - - - - - - - - - - - - - - -
echo ybtcloud-file-service-1.0-SNAPSHOT.jar
xcopy D:\ProgramFiles\Jenkins\workspace\Jenkins\.jenkins\workspace\ybtcloud\ybtcloud-file-center\ybtcloud-file-service\target\ybtcloud-file-service-1.0-SNAPSHOT.jar D:\ybtcloud\ybtcloud-file\ /Y
cd D:\ybtcloud\ybtcloud-file\
start C:\ProgramFiles\Java\jdk1.8.0_181\bin\javaw -Xms256m -Xmx512m -Dspring.profiles.active=prod -jar ybtcloud-file-service-1.0-SNAPSHOT.jar &
echo - - - - - - - - - - - - - - - - - ybtcloud-file-service-1.0-SNAPSHOT.jar 启动成功! - - - - - - - - - - - - - - - - -
echo ybtcloud-form-service-1.0-SNAPSHOT.jar
xcopy D:\ProgramFiles\Jenkins\workspace\Jenkins\.jenkins\workspace\ybtcloud\ybtcloud-form\ybtcloud-form-service\target\ybtcloud-form-service-1.0-SNAPSHOT.jar D:\ybtcloud\ybtcloud-form\ /Y
cd D:\ybtcloud\ybtcloud-form\
start C:\ProgramFiles\Java\jdk1.8.0_181\bin\javaw -Xms256m -Xmx512m -Dspring.profiles.active=prod -jar ybtcloud-form-service-1.0-SNAPSHOT.jar &
echo - - - - - - - - - - - - - - - - - ybtcloud-form-service-1.0-SNAPSHOT.jar 启动成功! - - - - - - - - - - - - - - - - -
echo imq-admin.jar
xcopy D:\ProgramFiles\Jenkins\workspace\Jenkins\.jenkins\workspace\ybtcloud\ybtcloud-imq\imq-admin\target\imq-admin.jar D:\ybtcloud\ybtcloud-imq\ /Y
cd D:\ybtcloud\ybtcloud-imq\
start C:\ProgramFiles\Java\jdk1.8.0_181\bin\javaw -Xms256m -Xmx512m -Dspring.profiles.active=prod -jar imq-admin.jar &
echo - - - - - - - - - - - - - - - - - imq-admin.jar 启动成功! - - - - - - - - - - - - - - - - -
echo ybtcloud-ncqc-service-1.0-SNAPSHOT.jar
xcopy D:\ProgramFiles\Jenkins\workspace\Jenkins\.jenkins\workspace\ybtcloud\ybtcloud-ncqc\ybtcloud-ncqc-service\target\ybtcloud-ncqc-service-1.0-SNAPSHOT.jar D:\ybtcloud\ybtcloud-ncqc\ /Y
cd D:\ybtcloud\ybtcloud-ncqc\
start C:\ProgramFiles\Java\jdk1.8.0_181\bin\javaw -Xms256m -Xmx512m -Dspring.profiles.active=prod -jar ybtcloud-ncqc-service-1.0-SNAPSHOT.jar &
echo - - - - - - - - - - - - - - - - - ybtcloud-ncqc-service-1.0-SNAPSHOT.jar 启动成功! - - - - - - - - - - - - - - - - -
echo ybtcloud-plt-service-1.0-SNAPSHOT.jar
xcopy D:\ProgramFiles\Jenkins\workspace\Jenkins\.jenkins\workspace\ybtcloud\ybtcloud-plt\ybtcloud-plt-service\target\ybtcloud-plt-service-1.0-SNAPSHOT.jar D:\ybtcloud\ybtcloud-plt\ /Y
cd D:\ybtcloud\ybtcloud-plt\
start C:\ProgramFiles\Java\jdk1.8.0_181\bin\javaw -Xms256m -Xmx512m -Dspring.profiles.active=prod -jar ybtcloud-plt-service-1.0-SNAPSHOT.jar &
echo - - - - - - - - - - - - - - - - - ybtcloud-plt-service-1.0-SNAPSHOT.jar 启动成功! - - - - - - - - - - - - - - - - -
echo ybtcloud-pve-service-1.0-SNAPSHOT.jar
xcopy D:\ProgramFiles\Jenkins\workspace\Jenkins\.jenkins\workspace\ybtcloud\ybtcloud-pve\ybtcloud-pve-service\target\ybtcloud-pve-service-1.0-SNAPSHOT.jar D:\ybtcloud\ybtcloud-pve\ /Y
cd D:\ybtcloud\ybtcloud-pve\
start C:\ProgramFiles\Java\jdk1.8.0_181\bin\javaw -Xms256m -Xmx512m -Dspring.profiles.active=prod -jar ybtcloud-pve-service-1.0-SNAPSHOT.jar &
echo - - - - - - - - - - - - - - - - - ybtcloud-pve-service-1.0-SNAPSHOT.jar 启动成功! - - - - - - - - - - - - - - - - -
echo ybtcloud-qcp-service-1.0-SNAPSHOT.jar
xcopy D:\ProgramFiles\Jenkins\workspace\Jenkins\.jenkins\workspace\ybtcloud\ybtcloud-qcpmanage\ybtcloud-qcp-service\target\ybtcloud-qcp-service-1.0-SNAPSHOT.jar D:\ybtcloud\ybtcloud-qcp\ /Y
cd D:\ybtcloud\ybtcloud-qcp\
start C:\ProgramFiles\Java\jdk1.8.0_181\bin\javaw -Xms256m -Xmx512m -Dspring.profiles.active=prod -jar ybtcloud-qcp-service-1.0-SNAPSHOT.jar &
echo - - - - - - - - - - - - - - - - - ybtcloud-qcp-service-1.0-SNAPSHOT.jar 启动成功! - - - - - - - - - - - - - - - - -
echo ybtcloud-qcs-service-1.0-SNAPSHOT.jar
xcopy D:\ProgramFiles\Jenkins\workspace\Jenkins\.jenkins\workspace\ybtcloud\ybtcloud-qcs-parent\ybtcloud-qcs-service\target\ybtcloud-qcs-service-1.0-SNAPSHOT.jar D:\ybtcloud\ybtcloud-qcs\ /Y
cd D:\ybtcloud\ybtcloud-qcs\
start C:\ProgramFiles\Java\jdk1.8.0_181\bin\javaw -Xms256m -Xmx512m -Dspring.profiles.active=prod -jar ybtcloud-qcs-service-1.0-SNAPSHOT.jar &
echo - - - - - - - - - - - - - - - - - ybtcloud-qcs-service-1.0-SNAPSHOT.jar 启动成功! - - - - - - - - - - - - - - - - -
echo ybtcloud-teo-service-1.0-SNAPSHOT.jar
xcopy D:\ProgramFiles\Jenkins\workspace\Jenkins\.jenkins\workspace\ybtcloud\ybtcloud-teo\ybtcloud-teo-service\target\ybtcloud-teo-service-1.0-SNAPSHOT.jar D:\ybtcloud\ybtcloud-teo\ /Y
cd D:\ybtcloud\ybtcloud-teo\
start C:\ProgramFiles\Java\jdk1.8.0_181\bin\javaw -Xms256m -Xmx512m -Dspring.profiles.active=prod -jar ybtcloud-teo-service-1.0-SNAPSHOT.jar &
echo - - - - - - - - - - - - - - - - - ybtcloud-teo-service-1.0-SNAPSHOT.jar 启动成功! - - - - - - - - - - - - - - - - -