最近有svn版本管理工具切换到git,自动化部署须要修改成从git拉取代码,下面是修改的步骤:css
首先展现一下构建页面的效果:java
看完构建页面的效果了,下面来看配置:python
一、参数设置(包含projectname参数关联type参数):git
包含projectname参数关联type参数web
SSHServer参数关联projectname参数bash
设置其余参数服务器
二、源码拉取:app
三、构建环境:webapp
四、构建步骤:svn
4.一、把须要的ant编译的build.xml(build.xml的代码上一篇有给出过,这里就不贴出来了)复制到workspace里面
if "%firsttime%"=="--select--" exit 1 if %projectname%==SAS (copy "%JENKINS_HOME%"\workspace\build-SAS.xml "%WORKSPACE%"\build.xml /y) else (copy "%JENKINS_HOME%"\workspace\build-test.xml "%WORKSPACE%"\build.xml /y) if not exist "%WORKSPACE%"\WebRoot\WEB-INF\classes mkdir "%WORKSPACE%"\WebRoot\WEB-INF\classes ::if not exist "%WORKSPACE%"\update mkdir "%WORKSPACE%"\update
4.二、把git增量文件做为清单列入文本
#\!/bin/bash cd "$WORKSPACE" git checkout $GitBranch git diff $from_commitid $to_commitid --name-only>compile_list.txt
4.三、遍历工做目录按清单文本(代码)
set stringName="%WORKSPACE%"\compile_list.txt set stringName1="%WORKSPACE%"\filelist.txt cd "%WORKSPACE%" python C:\loop.py compile_list.txt filelist.txt @echo off SET TheStart="%WORKSPACE%"\ (FOR /f "delims=" %%i IN (filelist.txt) DO ( ECHO %TheStart%%%i ))>New_list.txt @echo off (for /f "delims=" %%i in (New_list.txt) do ( set str=%%i SetLocal EnableDelayedExpansion set str=!str:/=\! echo !str!|find ".java">nul && set str=!str:.java=.class! && set str=!str:src=WebRoot\WEB-INF\classes! echo !str!|find "\src">nul && set str=!str:src=WebRoot\WEB-INF\classes! echo !str! EndLocal ))>newlist.txt && echo running rem 把配置文件去掉xml和properties文件 (for /f "delims=" %%a in ('findstr /i /v /c:".properties" "newlist.txt"') do ( SetLocal EnableDelayedExpansion echo %%a EndLocal ))>compile_list.txt (for /f "delims=" %%a in ('findstr /i /v /c:"\test" "compile_list.txt"') do ( SetLocal EnableDelayedExpansion echo %%a EndLocal ))>compile_list0.txt (for /f "delims=" %%a in ('findstr /i /v /c:".xml" "compile_list0.txt"') do ( SetLocal EnableDelayedExpansion echo %%a EndLocal ))>compile1.txt (for /f "delims=" %%a in ('findstr /i /v /c:".propertites" "compile1.txt"') do ( SetLocal EnableDelayedExpansion echo %%a EndLocal ))>compile2.txt @echo on if "%projectname%" == "ADS" for /f "delims=" %%a in ('findstr /r "wtsd\\ads.*\.xml" "newlist.txt"') do ( SetLocal EnableDelayedExpansion echo %%a>>compile2.txt EndLocal ) move /y compile2.txt compile_list.txt set tempdir="%WORKSPACE%"\temp set localdir="%WORKSPACE%" set classesdir="%WORKSPACE%"\WebRoot\WEB-INF cd %localdir% if exist %tempdir% rd /s /Q %tempdir% for /f "delims=" %%i in (compile_list.txt) do ( if "%%i"=="" goto end set fullpath=%%i call :export %%i ) set path=%path%;c:\program files\winrar cd "%WORKSPACE%"\temp\WebRoot dir /a-d /s /b>"%WORKSPACE%"\list.xls winrar a -r -m3 -ed WebRoot.zip .\* xcopy "%JENKINS_HOME%"\jobs\%JOB_NAME%\builds\%BUILD_NUMBER%\log "%WORKSPACE%"\ /s/e/y findstr /c:"svn: E" "%WORKSPACE%"\log >nul 2>nul if %ERRORLEVEL%==0 exit 1 findstr /c:"不包含文件" "%WORKSPACE%"\log >nul 2>nul if %ERRORLEVEL%==0 goto end ::findstr /c:"系统找不到" "%WORKSPACE%"\log >nul 2>nul ::if %ERRORLEVEL%==0 exit 1 :end exit 0 :export cd %classesdir% set filename=%~nx1 set fileonlyname=%~n1 call set "filepath=%%fullpath:%filename%=%%" call set "filepath=%%filepath:%localdir%=%%" if not exist %tempdir% mkdir %tempdir% set localfilepath=%localdir%%filepath% set tempfilepath=%tempdir%%filepath% if not exist %tempfilepath% mkdir %tempfilepath% set originfile=%localfilepath%%filename% set tempfile=%tempfilepath%%filename% call set "originfile=%originfile:\ =\%" call set "tempfile=%tempfile:\ =\%" copy %originfile% %tempfile% /y @echo off echo %localfilepath%%filename%|find /i "." >nul && echo 包含文件 || echo 不包含文件 @echo on cd %localfilepath% for /f "tokens=*" %%a in ('dir /s/b/a-d "*.class"') do ( echo %%~fa|find "%fileonlyname%$">nul && xcopy "%%a" %tempfilepath% ) goto :EOF
五、构建后步骤,把编译好的增量文件上传到服务器,并重启项目:
代码:
cd /scss/$projectname/webapps compiledir=$projectname if [ "$projectname" == "www" ];then compiledir=ww fi if [ "$projectname" == "err" ];then compiledir=we fi if [ "$projectname" == "werer" ];then compiledir=wer fi if [ $firsttime == Y ];then tar zcvf $compiledir.tar.gz $compiledir fi cp /scss/$projectname/webapps/temp/WebRoot/WebRoot.zip WebRoot.zip rm -rf temp unzip -o WebRoot.zip -d $compiledir pid=`ps aux|grep java|grep $projectname|grep -v grep|awk '{print $2}'` if [ "${pid}" ]; then kill -9 $pid else echo "server is not started,can startup" fi sh /scss/$projectname/bin/startup.sh sleep 10 pid=`ps aux|grep java|grep $projectname|grep -v grep|awk '{print $2}'` if [ "${pid}" ]; then echo "restart ok,server is running and pid=$pid" else echo "restart fail,server is not started" exit 1 fi