实现Jenkins+svn+bat批处理构建svn版本差异增量的自动化打zip包(优化版)

之前写过一个增量打zip包的,目前是需要做个一个增量svn打包优化版,包括svn单版本,连续版本,跳版本都能打包。

首先看一下已做好的构建页面:

实现Jenkins+svn+bat批处理构建svn版本差异增量的自动化打zip包(优化版)

 

 目开始看工程的配置及脚本:

1、构建参数设置:

实现Jenkins+svn+bat批处理构建svn版本差异增量的自动化打zip包(优化版)

 

 实现Jenkins+svn+bat批处理构建svn版本差异增量的自动化打zip包(优化版)

实现Jenkins+svn+bat批处理构建svn版本差异增量的自动化打zip包(优化版)

实现Jenkins+svn+bat批处理构建svn版本差异增量的自动化打zip包(优化版)

 实现Jenkins+svn+bat批处理构建svn版本差异增量的自动化打zip包(优化版)

 

 实现Jenkins+svn+bat批处理构建svn版本差异增量的自动化打zip包(优化版)

实现Jenkins+svn+bat批处理构建svn版本差异增量的自动化打zip包(优化版)

  groovy部分脚本:

实现Jenkins+svn+bat批处理构建svn版本差异增量的自动化打zip包(优化版)
if (type.equals("APP")) {  if (phase.equals("APP_COMMON")) {
return ["--select--","Common","BJ_Personal","DL_Personal","GanZ_Personal","GZ_Personal","HF_Personal","NB_Personal","NJ_Personal","NC_Personal","SuZ_Personal","SY_Personal","SJZ_Personal","SZ_Personal","WH_Personal","WX_Personal","XA_Personal","QD_Personal","ZZ_Personal","TJ_Personal","CD_Personal_Windows","SX_Personal"]
}else if (phase.equals("wanglin")){
return ["--select--","Common","BJ_Personal","DL_Personal","GanZ_Personal","GZ_Personal","HF_Personal","NB_Personal","NC_Personal","SuZ_Personal","SY_Personal","SJZ_Personal","SZ_Personal","WH_Personal","WX_Personal","XA_Personal","QD_Personal","ZZ_Personal","TJ_Personal"]
}else if (phase.equals("baijiaojiao")){
return ["--select--","Common","BJ_Personal","DL_Personal","GanZ_Personal","GZ_Personal","HF_Personal","NB_Personal","NC_Personal","SuZ_Personal","SY_Personal","SJZ_Personal","SZ_Personal","WH_Personal","WX_Personal","XA_Personal","QD_Personal","ZZ_Personal","TJ_Personal"]
}else {
return ["SZ"]
} 
} else if (type.equals("SO") ) {  if (SO.equals("personalDll")) {
  return ["--select--","BJ","DL","GZ","HF","NC","NJ","SuZ","SY","SJZ","SZ","QD","WH","WX","XA","ZZ","TJ"]  
} else {
return ["--select--"]
}
}   else {  
  return ["--select--"]  
}
View Code

实现Jenkins+svn+bat批处理构建svn版本差异增量的自动化打zip包(优化版)

 实现Jenkins+svn+bat批处理构建svn版本差异增量的自动化打zip包(优化版)

 

 实现Jenkins+svn+bat批处理构建svn版本差异增量的自动化打zip包(优化版)

 实现Jenkins+svn+bat批处理构建svn版本差异增量的自动化打zip包(优化版)

 

 实现Jenkins+svn+bat批处理构建svn版本差异增量的自动化打zip包(优化版)

 实现Jenkins+svn+bat批处理构建svn版本差异增量的自动化打zip包(优化版)

 实现Jenkins+svn+bat批处理构建svn版本差异增量的自动化打zip包(优化版)

 

 2、构建环境:每次构建前把构建目录清空

实现Jenkins+svn+bat批处理构建svn版本差异增量的自动化打zip包(优化版)

 

 3、构建步骤:

使用批处理脚本实现

实现Jenkins+svn+bat批处理构建svn版本差异增量的自动化打zip包(优化版)

 

 脚本完整如下:

实现Jenkins+svn+bat批处理构建svn版本差异增量的自动化打zip包(优化版)
::disk是我上面设置的参数,是指打的包将要存放在哪个磁盘,Jenkins构建使用的目录
set JenkinsGaia=%disk%:\JenkinsGaia
::sources目录是作为构建后打包的备份目录
set sources=%JenkinsGaia%\sources
::svnupdate是构建使用目录,因为我本机有全量自动化打包的目录,为了区分就建了这个目录
set svnupdate=%JenkinsGaia%\svnupdate
::temp是每次构建使用的临时目录
set tempdir=%svnupdate%\temp
if not exist %JenkinsGaia% mkdir %JenkinsGaia%
if not exist %sources% mkdir %sources%
if not exist %svnupdate% mkdir %svnupdate%
if exist %tempdir% rd /s /Q %tempdir%
if exist %svnupdate% rd /s /q %svnupdate%
md %svnupdate%
if %type%==APP (if %phase%==SZ ( set folder=%city%/HTML/sources/%APPbranch%) else ( set folder=%phase%/%city%/HTML/sources/%APPbranch%))

if %type%==SO (if %SO%==personalDll ( set folder=%SO%/%city%/trunk)else ( if %SO%==Devices ( set folder=%SO%/%Devices%/trunk)else ( set folder=%SO%/trunk)))
rem if %DLL%==差异驱动和配置文件 set "folder=%folder: =%"
if %type%==browser set folder=%browser%
set url=http://192.168.0.174/svn/Gaia/%type%/%folder%

chcp 65001
set version=%version:,=,%
set version=%version:-=-%
set vu=%version%
chcp 936
echo "%version%" | find "-" > null
if %errorlevel% neq 0 (
set x=0
)
echo "%version%" | find "," > null
if %errorlevel% equ 0 (
set x=0
goto :loop
)
echo "%version%" | find "-" > null
if %errorlevel% equ 0 (
set x=1
goto :goon
)
:loop
if "%version%" =="" goto :jump
setlocal EnableDelayedExpansion
for /f "delims=,, tokens=1,*" %%i in ("%version%") do (


call :jumptoexport %%i
set version=%%j
goto loop

)
:jumptoexport
rem 比较差异文件
::版本起始-1是因为下面使用svn命令行比较差异文件时是不包括开始版本的,-1之后的参数放到svn比较差异文件的命令里面,参数就不用往前挪版本,开发给什么版本到什么版本直接填入参数就好
set /a version_up=%1-1
set to_version=%1
if "%to_version%" NEQ "HEAD" goto NOHEAD
if "%to_version%"=="HEAD" svn log -r %to_version%:1 %url% >%svnupdate%\updatelog.txt & for /f "delims=" %%i in (%svnupdate%\updatelog.txt) do (
for /f "tokens=1,2,3,4 delims=|" %%a in ("%%i") do (set a1=%%a && echo %%a|find "r">nul && goto next
)
)
:next
for /f "tokens=1,2 delims=r" %%a in ("%a1%") do (set a1=%%a)
set "a1=%a1: =%"

set to_version=%a1%
set /a version_up=%to_version%-1
set "vu=%vu:HEAD=%"
set  vu=%vu%%a1%
:NOHEAD
rem 把差异清单导入到txt文件中
set stringName=%svnupdate%\file_list.txt
set stringName1=%svnupdate%\filelist.txt
call svn diff -r %version_up%:%to_version% --summarize %url% > %stringName% 
python C:\loop.py %stringName% %stringName1%
rem 导出差异文件
for /f "delims=" %%a in (%stringName1%) do (
     
     if '%%a'=='' goto end
     call :singleexport %%a

)  
goto :EOF
:singleexport
set updatetype=%1
if %updatetype%==D goto :EOF
set fullpath=%2

if %fullpath%==%url% goto :EOF
if %fullpath%==%url%/DLL goto :EOF
if %fullpath%==%url%/dll goto :EOF

set filename=%~nx2
echo "%filename%"|find "." >nul
if "%errorlevel%" NEQ "0" goto :EOF
call set "filepath=%%fullpath:%filename%=%%"
call set "filepath=%%filepath:%url%=%%"
call set "filepath=%%filepath:/=\%%"
if not exist %tempdir% mkdir %tempdir%
set tempfilepath=%tempdir%%filepath%
echo "%tempfilepath%"|find "\DLL">nul&& call set tempfilepath=%%tempfilepath:\DLL=\dll%%

if not exist "%tempfilepath%" mkdir "%tempfilepath%" 
svn export -r %to_version% %fullpath% %tempfilepath%%filename% --force
goto :EOF





goto :jump
:goon
for /f "delims=-, tokens=1,2" %%i in ("%version%") do (
set from_version=%%i
set to_version=%%j
)
set /a from_version_up=%from_version%-1




rem 比较差异文件
set stringName=%svnupdate%\file_list.txt
set stringName1=%svnupdate%\filelist.txt
svn log -r %to_version%:%from_version% %url% >%svnupdate%\updatelog.txt
svn diff -r %from_version_up%:%to_version% --summarize %url% > %stringName% --username luokc --password luokc!@34
python C:\loop.py %stringName% %stringName1%
rem 导出差异文件
for /f "delims=" %%i in (%stringName1%) do (
     
     if '%%i'=='' goto end
     call :export %%i

)
for /f "delims=" %%i in (%svnupdate%\updatelog.txt) do (
for /f "tokens=1,2,3,4 delims=|" %%a in ("%%i") do (set a1=%%a && echo %%a|find "r">nul && goto next
)
)
:next
for /f "tokens=1,2 delims=r" %%a in ("%a1%") do (set a1=%%a)
set "a1=%a1: =%"
:jump
set path=%path%;c:\program files\winrar
%disk%:
cd %svnupdate%
if %type%==APP mkdir %svnupdate%\app
set update=%date:~0,4%%date:~5,2%%date:~8,2%%time:~0,2%%time:~3,2%%time:~6,2%
set update=%update: =0%

if %type%==APP ( if %x% equ 0 ( set updatezip=app_%city%_%vu%_%update%.zip ) else ( set updatezip=app_%city%_%from_version%-%a1%_%update%.zip))
if %type%==SO (if %SO%==personalDll ( if %x% equ 0 ( set updatezip=dll_%SO%_%city%_%vu%_%update%.zip ) else ( set updatezip=dll_%SO%_%city%_%from_version%-%a1%_%update%.zip)) else (if %SO%==差异驱动和配置文件 ( if %x% equ 0 ( set updatezip=dll_%SO%_%差异驱动和配置文件%_%vu%_%update%.zip ) else ( set updatezip=dll_%SO%_%差异驱动和配置文件%_%from_version%-%a1%_%update%.zip)) else ( if %x% equ 0 ( set updatezip=dll_%SO%_%vu%_%update%.zip ) else ( set updatezip=dll_%SO%_%from_version%-%a1%_%update%.zip))))
if %type%==browser ( if %x% equ 0 ( set updatezip=%browser%_%vu%_%update%.zip ) else ( set updatezip=%browser%_%from_version%-%a1%_%update%.zip ) )
mkdir %update%
if %type%==APP ( xcopy /s/e/y %tempdir% %svnupdate%\app\ ) else ( xcopy /s/e/y %tempdir% %svnupdate%\%update%\ )
if %type% NEQ APP cd %svnupdate%\%update%
if "%type%" == "APP" ( winrar a -r -m3 -ed %updatezip% .\app\* ) else ( winrar a -r -m3 -ed %updatezip% * && xcopy /s/e/y %updatezip% %svnupdate%\ && cd %svnupdate%\ )

if %type%==APP ( rd /s /Q app )
rd /s /Q %update% 

xcopy /s/y %svnupdate%\%updatezip% %sources%\
dir %sources%\*.zip /O:-D >%sources%\file.txt
%disk%:
cd %sources%
for /F "skip=25 tokens=4" %%a in (%sources%\file.txt) do @if exist %%a del %%a
xcopy  "%JENKINS_HOME%"\jobs\%JOB_NAME%\builds\%BUILD_NUMBER%\log %svnupdate%\ /s/e/y
xcopy  %svnupdate%\%updatezip% "%WORKSPACE%"\ /y
findstr /c:"svn: E" %svnupdate%\log >nul 2>nul
if %ERRORLEVEL%==0 exit 1
findstr /c:"系统找不到" %svnupdate%\log >nul 2>nul
if %ERRORLEVEL%==0 exit 1
:end
exit 0
:export
set updatetype=%1
if %updatetype%==D goto:EOF
set fullpath=%2



if %fullpath%==%url% goto :EOF
if %fullpath%==%url%/DLL goto :EOF
if %fullpath%==%url%/dll goto :EOF

set filename=%~nx2
echo "%filename%"|find "." >nul
if "%errorlevel%" NEQ "0" goto :EOF
call set "filepath=%%fullpath:%filename%=%%"
call set "filepath=%%filepath:%url%=%%"
call set "filepath=%%filepath:/=\%%"
if not exist %tempdir% mkdir %tempdir%
set tempfilepath=%tempdir%%filepath%
echo "%tempfilepath%"|find "\DLL">nul&& call set tempfilepath=%%tempfilepath:\DLL=\dll%%

if not exist "%tempfilepath%" mkdir "%tempfilepath%" 
svn export -r %to_version% %fullpath% %tempfilepath%%filename% --force
goto :EOF
View Code

其中的loop.py文件python脚本,服务器需要安装有python,目前我用的是python2.7

#coding=utf-8
import sys
import urllib
import codecs
a = sys.argv[1] #批处理输入参数1
b = sys.argv[2] #批处理输入参数2

f=open(a,"r")
line=f.readline()
fx = codecs.open(b, 'wb+', 'gb2312')
while line:
url = urllib.unquote(line)+"\r\n"
content = unicode(url,"utf-8")

fx.write(content)
line = f.readline()
fx.close()
f.close()

4、构建后操作(可有可无此步骤,不用就忽略此步骤),把打好的包推送到自己电脑,自己电脑要开了FTP服务

实现Jenkins+svn+bat批处理构建svn版本差异增量的自动化打zip包(优化版)

 

 到此结束。

上一篇:自动驾驶3D标注工具bat-3d安装与使用说明


下一篇:window 获取文件md5值dos 脚本