基于Maven+SVN自动封装

基于Maven+SVN自动打包

 

目前我在新公司推行使用maven进行工程构建和管理,但是目前所有的测试环境和生成环境任然是WINDOWS,所以以前写的linux下自动构建打包的脚本无用了,今天写了个bat的的打包脚本,主要是用于测试人员,直接通过脚本自动打包测试用。免去开发人员打包在传文件的麻烦无聊事情,这里记录下。

 

@echo off
rem Package project with maven+svn for test team.
rem Just need your computer install JDK(1.6)+MAVEN(3)+SVN-Client
rem @author: zhangpu
rem @date: 2013-2-4

echo [INFO] Package project with maven+svn for test team.

if "%JAVA_HOME%" == "" goto java_env_error
if "%M2_HOME%" == "" goto maven_env_error
set workspace=%~dp0
FOR /F "delims=" %%I IN ("svn.exe") DO (if exist %%~$PATH:I ( set svn_export=1 &break ))
if %svn_export% equ 1 (goto pre_svn_export) else (goto do_ignore_svn)

:pre_svn_export
set svn_url=%1
set svn_username=%2
set svn_password=%3
if "%svn_url%" == "" ( echo [INFO] Please input project svn url: &set /p svn_url=)
if "%svn_username%" == "" ( echo [INFO] Please input your svn-username: &set /p svn_username=)
if "%svn_password%" == "" ( echo [INFO] Please input your svn-password: &set /p svn_password=)
if "%svn_url%" == "" (echo [WARN] project svn url does not exsit!! &goto :do_ignore_svn)
if "%svn_username%" == "" (echo [WARN] username not exsit!! &goto :do_ignore_svn)
if "%svn_password%" == "" (echo [WARN] password not exsit!! &goto :do_ignore_svn)
echo [INFO] Project_SVN_URL: %svn_url%
echo [INFO] SVN_USERNAME: %svn_username%
goto do_svn_export

:do_svn_export
if exist %workspace%src (rd /s /q %workspace%src &echo [INFO] clean and delete src)
if exist %workspace%target (rd /s /q %workspace%target &echo [INFO] clean and delete target)
if exist %workspace%pom.xml (del /q %workspace%pom.xml &echo [INFO] clean and delete pom.xml)
svn export -q --force --username %svn_username% --password %svn_password% %svn_url% %workspace%
echo [INFO] Finished export source from svn server.
goto do_mvn_package

:do_ignore_svn
echo [WARN] SVN-Client is not found or svn parameters error, ignore source export from svn server, package directly. &goto do_mvn_package

:do_mvn_package
call mvn clean package -Dmaven.test.skip=true
goto okEnd

:java_env_error
echo [ERROR] The JAVA_HOME environment variable is not defined correctly
goto paramsError

:maven_env_error
echo [ERROR] The M2_HOME environment variable is not defined correctly
goto paramsError

:okEnd
echo [INFO] Finished Auto-Package(SVN Auto Export + Maven Package)

:paramsError
pause

 

相关内容推荐