`

Ant 整合Jenkins自动构建

    博客分类:
  • Ant
 
阅读更多

Jenkins安装

    下载jenkins.war包,运行java -jar jenkins.war,即可访问http://localhost:8080/访问jenkins。

    或者将jenkins.war包放在Tomcat的Webapp下,启动Tomcat,访问http://localhost:8080/jenkins/。

    本例产用后者。

 

    1. 在首页选择系统管理,再右侧页面中选择管理插件。

        在可选插件中选择要安装的插件,下表为本次测试中已安装的插件,有些为默认已安装的插件。

 

插件

名称
版本   启用   Pinned   
mailer 1.4 true false
external-monitor-job 1.1 true false
ldap 1.1 true false
pam-auth 1.0 true false
javadoc 1.0 true false
maven-plugin 1.499 true false
ant 1.1 true false
analysis-core 1.48 true false
checkstyle 3.32 true false
cvs 1.6 true false
deploy 1.9 true false
jquery 1.7.2-1 true false
junit-attachments 1.3 true false
ssh-slaves 0.22 true false
subversion 1.39 true false
translation 1.8 true false
email-ext 2.25 true false

 

 

 

    2.进入jenkins首页,选择新建JOB,填写一个JOB名称,选择“构建一个自由风格的软件项目”。

       然后进入配置页面,也可以首页选择项目,然后选择配置进入此页面。

 

      本例的配置如下:

        1) 源码管理选择Subversion

                Repository Url:https://localhost/svn/Diary/trunk/Diary

 

        2) 构建触发器

                选择Poll SCM

                日程表:* * * * * (表示每分钟都比较,有更改就构建)

 

        3) 构建

                增加构建步骤:Invoke Ant

                Targets:(什么也没写,默认执行根目录下的build.xml)

 

        4) 构建后操作

                a. Publish Checkstyle analysis results

                    Checkstyle results:output/diary/checkstyle/checkstyle_report.xml

 

                b. Publish JUnit test result report

                    Test report XMLs:output/diary/test/data/*.xml

                    保留长的标准输出/错误 勾选

 

                c. Publish Javadoc

                    Javadoc directory:output/diary/docs

 

                d.Deploy war/ear to a container

                    WAR/EAR files:output/diary/diary-1.0.0.war

                    Container:Tomcat 6.x

                            Manager user name:admin

                            Manager password:*****

                            Tomcat URL:http://localhost:8080

 

                    (此处要配置Tomcat的角色和用户:

                        在Tomcat的安装目录下,找到conf/tomcat-users.xml,修改内容如下:

 

                           <role rolename="tomcat"/>

                           <role rolename="role1"/>

                           <role rolename="manager"/>

                           <role rolename="admin"/>

                           <user username="admin" password="admin" roles="admin,manager"/>

                           <user username="tomcat" password="tomcat" roles="tomcat"/>

                           <user username="both" password="tomcat" roles="tomcat,role1"/>

                           <user username="role1" password="tomcat" roles="role1"/>

 

                    )

 

                e. Editable Email Notification

                    Project Recipient List:要发送的邮件,可多个用逗号隔开

                     (此处要配置邮件服务,选择系统管理->系统设置:

                        Jenkins Location

                           Jenkins URL:http://localhost:8080/jenkins/

                        配置邮件通知

                        也可以Extended E-mail Notification中选择Override Global Settings覆盖的邮件通知。

                         在测试过程中,邮件通知中没有“发送者的邮箱地址”这一项,导致邮件一直不能发送,选择了Extended E-mail Notification中的Override Global Settings,在这里填写信息才将邮件发送成功。

 

                    )

 

附:

build.xml,增加War包:

<?xml version="1.0" encoding="UTF-8"?>
<project name="diary" default="total">

	<tstamp>
		<format property="build.latest.dir" pattern="yyyyMMddHHmmss"/>
		<format property="build.latest.date" pattern="yyyy-MM-dd"/>
		<format property="build.latest.time" pattern="HH:mm:ss"/>
	</tstamp>

	<property name="src.dir" location="src"/>
	
	<property name="web.dir" location="WebContent"/>
	
	<property name="webinf.dir" location="${web.dir}/WEB-INF"/>

	<property name="lib.dir" location="${webinf.dir}/lib"/>
	
	<property name="build.dir" location="build/classes"/>

	<!-- Output -->
	<property name="build.output" location="output"/>

	<property name="build.output.dir" location="${build.output}/diary"/>

	<!-- JavaDoc -->
	<property name="build.output.doc.dir" location="${build.output.dir}/docs"/>

	<!-- Test -->
	<property name="test.dir" location="test"/>

	<property name="build.output.test.dir" location="${build.output.dir}/test"/>

	<property name="build.output.test.data.dir" location="${build.output.test.dir}/data"/>

	<!-- CheckStyle -->
	<property name="build.output.checkstyle.dir" location="${build.output.dir}/checkstyle"/>

    <property name="checkstyle.xml" location="${build.output.checkstyle.dir}/checkstyle_checks.xml"/> 
	
    <property name="checkstyle.xsl" location="${build.output.checkstyle.dir}/checkstyle-frames.xsl"/> 

	<!-- Log -->
	<property name="build.output.log" location="${build.output}/output.log"/>

	<property name="build.output.log.verbose" location="${build.output}/output_verbose.log"/>

	<property name="build.output.log.datetime" value="[${build.latest.date} ${build.latest.time}] "/>

	<!-- Jar -->
	<property file="${src.dir}/base.properties"/>

	<property name="build.output.requires.dir" location="${build.output.dir}/requires"/>

	<fileset id="compile.jar" dir="${lib.dir}">
		<include name="commons-lang-2.4.jar"/>
	</fileset>

	<!-- 类路径 -->
	<path id="compile.classpath">
		<fileset refid="compile.jar"/>
	</path>

	<path id="test.classpath">
		<path refid="compile.classpath"/>
		<pathelement location="${lib.dir}/junit-4.10.jar"/>
		<pathelement location="${build.dir}"/> 
	</path>

	<path id="checkstyle.classpath">
		<pathelement location="${lib.dir}/checkstyle-5.6-all.jar"/>
	</path>
	
	
	<!-- 记录日志,日志保存到文件中 -->
	<record name="${build.output.log}" append="no"/>

	<record name="${build.output.log.verbose}" append="no" loglevel="verbose"/>

	<target name="total" depends="zip,war" description="构建完成">
		<echo>${build.output.log.datetime}构建完成!</echo>
	</target>
	
	<target name="war" depends="createjar,javadoc" description="生成War">
		<war destfile="${build.output.dir}/${project.name}-${project.version}.war" webxml="${webinf.dir}/web.xml" duplicate="fail">
		  <fileset file="${web.dir}/*.jsp"/>
		  <lib dir="${lib.dir}">
		  	<include name="commons-lang-2.4.jar"/>
		  </lib>
		  <classes dir="${build.dir}">
		  	<include name="diary/**/*"/>
		  	<include name="${build.dir}/test.property"/>
		  </classes>
		</war>
		<echo>${build.output.log.datetime}生成War完成!</echo>
	</target>

	<target name="zip" depends="createjar,javadoc" description="生成Zip">
		<zip destfile="${build.output.dir}/${project.name}-core-${project.version}.zip" duplicate="preserve">
			 <zipfileset dir="${build.output.dir}/docs" prefix="docs"/>
			 <zipfileset dir="${build.output.dir}/requires" prefix="requires"/>
			 <zipfileset file="${build.output.dir}/*.jar"/>
		</zip>
		<echo>${build.output.log.datetime}生成Zip完成!</echo>
	</target>

	<target name="createjar" depends="test" description="生成Jar">
		<manifest file="${build.output.dir}/MANIFEST.MF" encoding="utf-8">
			<attribute name="Built-By" value="${user.name}"/>
			<section name="${project.name}">
				<attribute name="Implementation-Title" value="${project.name}"/>
				<attribute name="Implementation-Version" value="${project.version}"/>
			</section>
		</manifest>
		<jar destfile="${build.output.dir}/${project.name}-core-${project.version}.jar" duplicate="preserve" compress="false" manifestencoding="utf-8" manifest="${build.output.dir}/MANIFEST.MF">
			<fileset dir="${build.dir}">
				<exclude name="test/**/*"/>
				<exclude name="test"/>
				<exclude name="checkstyle_checks.xml"/>
				<exclude name="checkstyle-frames.xsl"/>
				<exclude name="checkstyletask.properties"/>
				<exclude name="sun_checks.xml"/>
				<exclude name="checkstyle_checks.xml"/>
				<exclude name="base.properties"/>
			</fileset>
		</jar>
		<copy todir="${build.output.requires.dir}">
			<fileset refid="compile.jar"/>
		</copy>
		<echo>${build.output.log.datetime}生成Jar完成!</echo>
	</target>

	<target name="javadoc" depends="test" description="生成JavaDoc">  
        <javadoc  
            sourcepath="${src.dir}"  
            destdir="${build.output.doc.dir}"  
            packagenames="diary.*"  
            use="true"  
            version="true"  
            windowtitle="${project.name}"  
            failonerror="true">  
            <classpath refid="compile.classpath"/>  
        </javadoc> 
		<echo>${build.output.log.datetime}生成JavaDoc完成,详情可查看${build.output.doc.dir}/index.html!</echo>
    </target>

	<target name="test" depends="compilesrc,compiletest" description="批量测试,并生成html">  
        <junit printsummary="false" haltonfailure="false" errorProperty="test.failed" failureProperty="test.failed">  
            <classpath refid="test.classpath"/>  
            <formatter type="brief" usefile="false"/>  
            <formatter type="xml"/>  
			<!-- 在testcase定义的情况下,单独测试testcase -->
            <test name="${testcase}" todir="${build.output.test.data.dir}" if="testcase"/>  
			<!-- 批量测试 -->
            <batchtest todir="${build.output.test.data.dir}" unless="testcase">  
                <fileset dir="${build.dir}">  
                    <include name="**/*Test.class"/>  
                </fileset>  
            </batchtest>  
        </junit>  
        <junitreport todir="${build.output.test.data.dir}">  
            <fileset dir="${build.output.test.data.dir}">  
                <include name="TEST-*.xml"/>  
            </fileset>  
            <report format="frames" todir="${build.output.test.dir}"/>  
        </junitreport>  
        <fail if="test.failed">  
            ${build.output.log.datetime}批量测试,并生成html失败,详细可查看${build.output.test.dir}/index.html  
        </fail>  
        <echo>${build.output.log.datetime}批量测试,并生成html完成,详细可查看${build.output.test.dir}/index.html!</echo>  
    </target> 

	<target name="compiletest" depends="copytest,compilesrc" description="编译测试代码文件">
		<javac srcdir="${test.dir}" destdir="${build.dir}" includeAntRuntime="false" encoding="UTF-8">
			<include name="**/*.java"/>
			<classpath refid="test.classpath"/>
		</javac>
		<echo>${build.output.log.datetime}编译测试代码文件完成!</echo>
	</target>

	<target name="copytest" depends="init" description="复制测试代码资源文件到编译目录">
		<fileset dir="${test.dir}">
			<exclude name="**/*.java"/>
		</fileset>
		<echo>${build.output.log.datetime}复制测试代码资源文件到编译目录完成!</echo>
	</target>

	<target name="compilesrc" depends="checkstyle,copysrc" description="编译源代码文件">
		<javac srcdir="${src.dir}" destdir="${build.dir}" includeAntRuntime="false" encoding="UTF-8">
			<include name="**/*.java"/>
			<classpath refid="compile.classpath"/>
		</javac>
		<echo>${build.output.log.datetime}编译源代码文件完成!</echo>
	</target>

	<target name="copysrc" depends="init" description="复制源代码资源文件到编译目录">
		<copy todir="${build.dir}" includeemptydirs="false">
			<fileset dir="${src.dir}">
				<exclude name="**/*.java"/>
			</fileset>
		</copy>
		<echo>${build.output.log.datetime}复制源代码资源文件到编译目录完成!</echo>
	</target>

	<target name="checkstyle" depends="init" description="用Checkstyle校验源代码">
		<taskdef name="checkstyle"  classname="com.puppycrawl.tools.checkstyle.CheckStyleTask" classpathref="checkstyle.classpath"/> 
        <checkstyle    
            failOnViolation="false"      
            failureProperty="checkstyle.failed"     
            config="${src.dir}/sun_checks.xml">     
            <fileset dir="${src.dir}" includes="**/*.java"/>      
            <formatter type="plain"/>      
            <formatter type="xml" toFile="${build.output.checkstyle.dir}/checkstyle_report.xml"/>      
        </checkstyle>
		<xslt style="${checkstyle.xsl}"      
            in="${build.output.checkstyle.dir}/checkstyle_report.xml"      
            out="${build.output.checkstyle.dir}/checkstyle_report.html">    
        </xslt>
		<echo>${build.output.log.datetime}用Checkstyle校验源代码完成,详细信息查看${build.output.checkstyle.dir}/checkstyle_report.html!</echo>
    </target>

	<target name="init" depends="clean,cleanoutput" description="创建输出目录">
		<mkdir dir="${build.dir}"/>
		<mkdir dir="${build.output.dir}"/>
		<mkdir dir="${build.output.doc.dir}"/>
		<mkdir dir="${build.output.test.dir}"/>
		<mkdir dir="${build.output.test.data.dir}"/>
		<mkdir dir="${build.output.checkstyle.dir}"/>
		<copy todir="${build.output.checkstyle.dir}" overwrite="true">
			<fileset dir="${src.dir}">
				<include name="checkstyle-frames.xsl"/>
				<include name="checkstyle_checks.xml"/>
			</fileset>
			<filterset>
				<filter token="output.dir" value="${build.output.checkstyle.dir}"/>
			</filterset>
		</copy>
		<echo>${build.output.log.datetime}输出目录创建完成!</echo>
	</target>

	<target name="clean" description="清理编译目录">
		<delete includeemptydirs="true">
			<fileset dir="${build.dir}">
				<include name="**/*"/>
			</fileset>
		</delete>
		<echo>${build.output.log.datetime}编译目录清理完成!</echo>
	</target>

	<target name="cleanoutput" description="清理输出目录">		
		<delete includeemptydirs="true">
			<fileset dir="${build.output}">
				<exclude name="output*.log"/>
			</fileset>
		</delete>
		<echo>${build.output.log.datetime}输出目录清理完成!</echo>
	</target>
	
</project>

 输出:

构建出错后的输出,会发送邮件到指定邮箱:

控制台输出

Started by user anonymous
Building in workspace C:\Users\xujing\.jenkins\jobs\Diary\workspace
Updating https://localhost/svn/Diary/trunk/Diary
At revision 20
no change for https://localhost/svn/Diary/trunk/Diary since the previous build
No emails were triggered.
[workspace] $ cmd.exe /C '"ant.bat && exit %%ERRORLEVEL%%"'
Buildfile: C:\Users\xujing\.jenkins\jobs\Diary\workspace\build.xml

clean:
     [echo] [2013-01-21 15:50:49] 编译目录清理完成!

cleanoutput:
     [echo] [2013-01-21 15:50:49] 输出目录清理完成!

init:
    [mkdir] Created dir: C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary
    [mkdir] Created dir: C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary\docs
    [mkdir] Created dir: C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary\test
    [mkdir] Created dir: C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary\test\data
    [mkdir] Created dir: C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary\checkstyle
     [copy] Copying 2 files to C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary\checkstyle
     [echo] [2013-01-21 15:50:49] 输出目录创建完成!

checkstyle:
[checkstyle] Running Checkstyle 5.6 on 2 files
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\entity\Diary.java:0: Missing package-info.java file.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\entity\Diary.java:9: Missing a Javadoc comment.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\entity\Diary.java:11:1: File contains tab characters (this is the first instance).
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\entity\Diary.java:11:9: Missing a Javadoc comment.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\entity\Diary.java:13:9: Missing a Javadoc comment.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\entity\Diary.java:14:9: Missing a Javadoc comment.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\entity\Diary.java:15:9: Missing a Javadoc comment.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\entity\Diary.java:16:9: Missing a Javadoc comment.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\entity\Diary.java:18:9: Method 'getId' is not designed for extension - needs to be abstract, final or empty.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\entity\Diary.java:18:9: Missing a Javadoc comment.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\entity\Diary.java:22:9: Method 'setId' is not designed for extension - needs to be abstract, final or empty.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\entity\Diary.java:22:9: Missing a Javadoc comment.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\entity\Diary.java:22:27: Parameter id should be final.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\entity\Diary.java:22:34: 'id' hides a field.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\entity\Diary.java:26:9: Method 'getName' is not designed for extension - needs to be abstract, final or empty.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\entity\Diary.java:26:9: Missing a Javadoc comment.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\entity\Diary.java:30:9: Method 'setName' is not designed for extension - needs to be abstract, final or empty.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\entity\Diary.java:30:9: Missing a Javadoc comment.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\entity\Diary.java:30:29: Parameter name should be final.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\entity\Diary.java:30:36: 'name' hides a field.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\entity\Diary.java:34:9: Method 'getCreateTime' is not designed for extension - needs to be abstract, final or empty.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\entity\Diary.java:34:9: Missing a Javadoc comment.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\entity\Diary.java:38:9: Method 'setCreateTime' is not designed for extension - needs to be abstract, final or empty.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\entity\Diary.java:38:9: Missing a Javadoc comment.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\entity\Diary.java:38:35: Parameter createTime should be final.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\entity\Diary.java:38:40: 'createTime' hides a field.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\entity\Diary.java:42:9: Method 'getContent' is not designed for extension - needs to be abstract, final or empty.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\entity\Diary.java:42:9: Missing a Javadoc comment.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\entity\Diary.java:46:9: Method 'setContent' is not designed for extension - needs to be abstract, final or empty.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\entity\Diary.java:46:9: Missing a Javadoc comment.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\entity\Diary.java:46:32: Parameter content should be final.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\entity\Diary.java:46:39: 'content' hides a field.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\entity\Diary.java:50:9: Method 'toString' is not designed for extension - needs to be abstract, final or empty.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\entity\Diary.java:52: Line is longer than 80 characters (found 145).
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\service\DiaryService.java:0: File does not end with a newline.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\service\DiaryService.java:0: Missing package-info.java file.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\service\DiaryService.java:8: Missing a Javadoc comment.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\service\DiaryService.java:10:1: File contains tab characters (this is the first instance).
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\service\DiaryService.java:10:9: Method 'get' is not designed for extension - needs to be abstract, final or empty.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\service\DiaryService.java:10:9: Missing a Javadoc comment.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\service\DiaryService.java:10:26: Parameter name should be final.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\service\DiaryService.java:10:39: Parameter content should be final.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\service\DiaryService.java:21:9: Missing a Javadoc comment.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\service\DiaryService.java:21:33: Parameter args should be final.
     [xslt] Processing C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary\checkstyle\checkstyle_report.xml to C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary\checkstyle\checkstyle_report.html
     [xslt] Loading stylesheet C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary\checkstyle\checkstyle-frames.xsl
     [echo] [2013-01-21 15:50:49] 用Checkstyle校验源代码完成,详细信息查看C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary\checkstyle/checkstyle_report.html!

copysrc:
     [copy] Copying 6 files to C:\Users\xujing\.jenkins\jobs\Diary\workspace\build\classes
     [echo] [2013-01-21 15:50:49] 复制源代码资源文件到编译目录完成!

compilesrc:
    [javac] Compiling 2 source files to C:\Users\xujing\.jenkins\jobs\Diary\workspace\build\classes
     [echo] [2013-01-21 15:50:49] 编译源代码文件完成!

copytest:
     [echo] [2013-01-21 15:50:49] 复制测试代码资源文件到编译目录完成!

compiletest:
    [javac] Compiling 2 source files to C:\Users\xujing\.jenkins\jobs\Diary\workspace\build\classes
     [echo] [2013-01-21 15:50:49] 编译测试代码文件完成!

test:
    [junit] Testsuite: test.diary.core.entity.DiaryTest
    [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.124 sec
    [junit] 
    [junit] ------------- Standard Output ---------------
    [junit] diary.core.entity.Diary[id=ac1f64b3-5aa3-4bb5-bef2-97657b881eaf,name=测试名称1,createTime=Mon Jan 21 15:50:52 CST 2013,content=测试内容1]
    [junit] ------------- ---------------- ---------------
    [junit] Testsuite: test.diary.core.service.DiaryServiceTest
    [junit] Tests run: 1, Failures: 1, Errors: 0, Time elapsed: 0.01 sec
    [junit] 
    [junit] Testcase: testGet(test.diary.core.service.DiaryServiceTest):	FAILED
    [junit] 测试名称出错 expected:<测试名称[2]> but was:<测试名称[1]>
    [junit] junit.framework.ComparisonFailure: 测试名称出错 expected:<测试名称[2]> but was:<测试名称[1]>
    [junit] 	at test.diary.core.service.DiaryServiceTest.testGet(Unknown Source)
    [junit] 
    [junit] 
    [junit] Test test.diary.core.service.DiaryServiceTest FAILED
[junitreport] Processing C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary\test\data\TESTS-TestSuites.xml to C:\Users\xujing\AppData\Local\Temp\null274425186
[junitreport] Loading stylesheet jar:file:/D:/dev/ant/ant1.8.4/lib/ant-junit.jar!/org/apache/tools/ant/taskdefs/optional/junit/xsl/junit-frames.xsl
[junitreport] Transform time: 266ms
[junitreport] Deleting: C:\Users\xujing\AppData\Local\Temp\null274425186

BUILD FAILED
C:\Users\xujing\.jenkins\jobs\Diary\workspace\build.xml:166: [2013-01-21 15:50:49] 批量测试,并生成html失败,详细可查看C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary\test/index.html

Total time: 3 seconds
Build step 'Invoke Ant' marked build as failure
[CHECKSTYLE] Skipping publisher since build result is FAILURE
Recording test results
Publishing Javadoc
Email was triggered for: Failure
Sending email for trigger: Failure
Sending email to: 指定邮箱
Finished: FAILURE

 构建成功后的输出,不会发送邮件:

控制台输出

Started by user anonymous
Building in workspace C:\Users\xujing\.jenkins\jobs\Diary\workspace
Updating https://localhost/svn/Diary/trunk/Diary
At revision 21
no change for https://localhost/svn/Diary/trunk/Diary since the previous build
No emails were triggered.
[workspace] $ cmd.exe /C '"ant.bat && exit %%ERRORLEVEL%%"'
Buildfile: C:\Users\xujing\.jenkins\jobs\Diary\workspace\build.xml

clean:
     [echo] [2013-01-21 16:21:25] 编译目录清理完成!

cleanoutput:
     [echo] [2013-01-21 16:21:25] 输出目录清理完成!

init:
    [mkdir] Created dir: C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary
    [mkdir] Created dir: C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary\docs
    [mkdir] Created dir: C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary\test
    [mkdir] Created dir: C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary\test\data
    [mkdir] Created dir: C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary\checkstyle
     [copy] Copying 2 files to C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary\checkstyle
     [echo] [2013-01-21 16:21:25] 输出目录创建完成!

checkstyle:
[checkstyle] Running Checkstyle 5.6 on 2 files
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\entity\Diary.java:0: Missing package-info.java file.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\entity\Diary.java:9: Missing a Javadoc comment.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\entity\Diary.java:11:1: File contains tab characters (this is the first instance).
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\entity\Diary.java:11:9: Missing a Javadoc comment.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\entity\Diary.java:13:9: Missing a Javadoc comment.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\entity\Diary.java:14:9: Missing a Javadoc comment.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\entity\Diary.java:15:9: Missing a Javadoc comment.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\entity\Diary.java:16:9: Missing a Javadoc comment.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\entity\Diary.java:18:9: Method 'getId' is not designed for extension - needs to be abstract, final or empty.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\entity\Diary.java:18:9: Missing a Javadoc comment.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\entity\Diary.java:22:9: Method 'setId' is not designed for extension - needs to be abstract, final or empty.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\entity\Diary.java:22:9: Missing a Javadoc comment.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\entity\Diary.java:22:27: Parameter id should be final.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\entity\Diary.java:22:34: 'id' hides a field.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\entity\Diary.java:26:9: Method 'getName' is not designed for extension - needs to be abstract, final or empty.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\entity\Diary.java:26:9: Missing a Javadoc comment.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\entity\Diary.java:30:9: Method 'setName' is not designed for extension - needs to be abstract, final or empty.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\entity\Diary.java:30:9: Missing a Javadoc comment.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\entity\Diary.java:30:29: Parameter name should be final.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\entity\Diary.java:30:36: 'name' hides a field.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\entity\Diary.java:34:9: Method 'getCreateTime' is not designed for extension - needs to be abstract, final or empty.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\entity\Diary.java:34:9: Missing a Javadoc comment.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\entity\Diary.java:38:9: Method 'setCreateTime' is not designed for extension - needs to be abstract, final or empty.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\entity\Diary.java:38:9: Missing a Javadoc comment.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\entity\Diary.java:38:35: Parameter createTime should be final.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\entity\Diary.java:38:40: 'createTime' hides a field.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\entity\Diary.java:42:9: Method 'getContent' is not designed for extension - needs to be abstract, final or empty.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\entity\Diary.java:42:9: Missing a Javadoc comment.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\entity\Diary.java:46:9: Method 'setContent' is not designed for extension - needs to be abstract, final or empty.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\entity\Diary.java:46:9: Missing a Javadoc comment.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\entity\Diary.java:46:32: Parameter content should be final.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\entity\Diary.java:46:39: 'content' hides a field.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\entity\Diary.java:50:9: Method 'toString' is not designed for extension - needs to be abstract, final or empty.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\entity\Diary.java:52: Line is longer than 80 characters (found 145).
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\service\DiaryService.java:0: File does not end with a newline.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\service\DiaryService.java:0: Missing package-info.java file.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\service\DiaryService.java:8: Missing a Javadoc comment.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\service\DiaryService.java:10:1: File contains tab characters (this is the first instance).
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\service\DiaryService.java:10:9: Method 'get' is not designed for extension - needs to be abstract, final or empty.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\service\DiaryService.java:10:9: Missing a Javadoc comment.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\service\DiaryService.java:10:26: Parameter name should be final.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\service\DiaryService.java:10:39: Parameter content should be final.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\service\DiaryService.java:21:9: Missing a Javadoc comment.
[checkstyle] C:\Users\xujing\.jenkins\jobs\Diary\workspace\src\diary\core\service\DiaryService.java:21:33: Parameter args should be final.
     [xslt] Processing C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary\checkstyle\checkstyle_report.xml to C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary\checkstyle\checkstyle_report.html
     [xslt] Loading stylesheet C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary\checkstyle\checkstyle-frames.xsl
     [echo] [2013-01-21 16:21:25] 用Checkstyle校验源代码完成,详细信息查看C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary\checkstyle/checkstyle_report.html!

copysrc:
     [copy] Copying 6 files to C:\Users\xujing\.jenkins\jobs\Diary\workspace\build\classes
     [echo] [2013-01-21 16:21:25] 复制源代码资源文件到编译目录完成!

compilesrc:
    [javac] Compiling 2 source files to C:\Users\xujing\.jenkins\jobs\Diary\workspace\build\classes
     [echo] [2013-01-21 16:21:25] 编译源代码文件完成!

copytest:
     [echo] [2013-01-21 16:21:25] 复制测试代码资源文件到编译目录完成!

compiletest:
    [javac] Compiling 2 source files to C:\Users\xujing\.jenkins\jobs\Diary\workspace\build\classes
     [echo] [2013-01-21 16:21:25] 编译测试代码文件完成!

test:
    [junit] Testsuite: test.diary.core.entity.DiaryTest
    [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.093 sec
    [junit] 
    [junit] ------------- Standard Output ---------------
    [junit] diary.core.entity.Diary[id=8d4e306d-150f-4a7f-bb32-b003730e6840,name=测试名称1,createTime=Mon Jan 21 16:21:28 CST 2013,content=测试内容1]
    [junit] ------------- ---------------- ---------------
    [junit] Testsuite: test.diary.core.service.DiaryServiceTest
    [junit] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.007 sec
    [junit] 
[junitreport] Processing C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary\test\data\TESTS-TestSuites.xml to C:\Users\xujing\AppData\Local\Temp\null1418970787
[junitreport] Loading stylesheet jar:file:/D:/dev/ant/ant1.8.4/lib/ant-junit.jar!/org/apache/tools/ant/taskdefs/optional/junit/xsl/junit-frames.xsl
[junitreport] Transform time: 272ms
[junitreport] Deleting: C:\Users\xujing\AppData\Local\Temp\null1418970787
     [echo] [2013-01-21 16:21:25] 批量测试,并生成html完成,详细可查看C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary\test/index.html!

createjar:
      [jar] Building jar: C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary\diary-core-1.0.0.jar
     [copy] Copying 1 file to C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary\requires
     [echo] [2013-01-21 16:21:25] 生成Jar完成!

javadoc:
  [javadoc] Generating Javadoc
  [javadoc] Javadoc execution
  [javadoc] 正在装入软件包 diary.core.entity 的源文件...
  [javadoc] 正在装入软件包 diary.core.service 的源文件...
  [javadoc] 正在构造 Javadoc 信息...
  [javadoc] 标准 Doclet 版本 1.6.0_27
  [javadoc] 正在构建所有软件包和类的树...
  [javadoc] 正在生成 C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary\docs\diary/core/entity/\Diary.html...
  [javadoc] 正在生成 C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary\docs\diary/core/service/\DiaryService.html...
  [javadoc] 正在生成 C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary\docs\overview-frame.html...
  [javadoc] 正在生成 C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary\docs\diary/core/entity/\package-frame.html...
  [javadoc] 正在生成 C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary\docs\diary/core/entity/\package-summary.html...
  [javadoc] 正在生成 C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary\docs\diary/core/entity/\package-tree.html...
  [javadoc] 正在生成 C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary\docs\diary/core/service/\package-frame.html...
  [javadoc] 正在生成 C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary\docs\diary/core/service/\package-summary.html...
  [javadoc] 正在生成 C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary\docs\diary/core/service/\package-tree.html...
  [javadoc] 正在生成 C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary\docs\constant-values.html...
  [javadoc] 正在生成 C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary\docs\serialized-form.html...
  [javadoc] 正在生成 C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary\docs\diary/core/entity/\class-use\Diary.html...
  [javadoc] 正在生成 C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary\docs\diary/core/service/\class-use\DiaryService.html...
  [javadoc] 正在生成 C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary\docs\diary/core/entity/\package-use.html...
  [javadoc] 正在生成 C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary\docs\diary/core/service/\package-use.html...
  [javadoc] 正在构建所有软件包和类的索引...
  [javadoc] 正在生成 C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary\docs\overview-tree.html...
  [javadoc] 正在生成 C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary\docs\index-all.html...
  [javadoc] 正在生成 C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary\docs\deprecated-list.html...
  [javadoc] 正在构建所有类的索引...
  [javadoc] 正在生成 C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary\docs\allclasses-frame.html...
  [javadoc] 正在生成 C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary\docs\allclasses-noframe.html...
  [javadoc] 正在生成 C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary\docs\index.html...
  [javadoc] 正在生成 C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary\docs\overview-summary.html...
  [javadoc] 正在生成 C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary\docs\help-doc.html...
  [javadoc] 正在生成 C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary\docs\stylesheet.css...
     [echo] [2013-01-21 16:21:25] 生成JavaDoc完成,详情可查看C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary\docs/index.html!

zip:
      [zip] Building zip: C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary\diary-core-1.0.0.zip
     [echo] [2013-01-21 16:21:25] 生成Zip完成!

war:
      [war] Building war: C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary\diary-1.0.0.war
     [echo] [2013-01-21 16:21:25] 生成War完成!

total:
     [echo] [2013-01-21 16:21:25] 构建完成!

BUILD SUCCESSFUL
Total time: 6 seconds
[CHECKSTYLE] Collecting checkstyle analysis files...
[CHECKSTYLE] Finding all files that match the pattern output/diary/checkstyle/checkstyle_report.xml
[CHECKSTYLE] Parsing 1 files in C:\Users\xujing\.jenkins\jobs\Diary\workspace
[CHECKSTYLE] Successfully parsed file C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary\checkstyle\checkstyle_report.xml of module  with 44 warnings.
[CHECKSTYLE] Computing warning deltas based on reference build #39
Recording test results
Publishing Javadoc
Deploying C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary\diary-1.0.0.war to container Tomcat 6.x Remote
  Redeploying [C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary\diary-1.0.0.war]
  Undeploying [C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary\diary-1.0.0.war]
  Deploying [C:\Users\xujing\.jenkins\jobs\Diary\workspace\output\diary\diary-1.0.0.war]
No emails were triggered.
Finished: SUCCESS

 

也可以在build.xml中增加部署的代码,并测试部署是否成功,在Jenkins中去掉部署配置:

<?xml version="1.0" encoding="UTF-8"?>
<project name="diary" default="total">

	<tstamp>
		<format property="build.latest.dir" pattern="yyyyMMddHHmmss"/>
		<format property="build.latest.date" pattern="yyyy-MM-dd"/>
		<format property="build.latest.time" pattern="HH:mm:ss"/>
	</tstamp>

	<property name="src.dir" location="src"/>
	
	<property name="web.dir" location="WebContent"/>
	
	<property name="webinf.dir" location="${web.dir}/WEB-INF"/>

	<property name="lib.dir" location="${webinf.dir}/lib"/>
	
	<property name="build.dir" location="build/classes"/>

	<!-- Output -->
	<property name="build.output" location="output"/>

	<property name="build.output.dir" location="${build.output}/diary"/>

	<!-- JavaDoc -->
	<property name="build.output.doc.dir" location="${build.output.dir}/docs"/>

	<!-- Test -->
	<property name="test.dir" location="test"/>

	<property name="build.output.test.dir" location="${build.output.dir}/test"/>

	<property name="build.output.test.data.dir" location="${build.output.test.dir}/data"/>

	<!-- CheckStyle -->
	<property name="build.output.checkstyle.dir" location="${build.output.dir}/checkstyle"/>

    <property name="checkstyle.xml" location="${build.output.checkstyle.dir}/checkstyle_checks.xml"/> 
	
    <property name="checkstyle.xsl" location="${build.output.checkstyle.dir}/checkstyle-frames.xsl"/> 

	<!-- Log -->
	<property name="build.output.log" location="${build.output}/output.log"/>

	<property name="build.output.log.verbose" location="${build.output}/output_verbose.log"/>

	<property name="build.output.log.datetime" value="[${build.latest.date} ${build.latest.time}] "/>

	<!-- Jar -->
	<property file="${src.dir}/base.properties"/>

	<property name="build.output.requires.dir" location="${build.output.dir}/requires"/>
	
	<!-- deploy -->
	<property name="url.server" value="localhost"/>
	
	<property name="url.port" value="8080"/>
	
	<property name="server.address" value="D:/dev/tomcat/tomcat6035test/webapps"/>
	
	<property name="application.url" value="http://${url.server}:${url.port}/${project.name}-${project.version}"/>
	
	

	<fileset id="compile.jar" dir="${lib.dir}">
		<include name="commons-lang-2.4.jar"/>
	</fileset>

	<!-- 类路径 -->
	<path id="compile.classpath">
		<fileset refid="compile.jar"/>
	</path>

	<path id="test.classpath">
		<path refid="compile.classpath"/>
		<pathelement location="${lib.dir}/junit-4.10.jar"/>
		<pathelement location="${build.dir}"/> 
	</path>

	<path id="checkstyle.classpath">
		<pathelement location="${lib.dir}/checkstyle-5.6-all.jar"/>
	</path>
	
	
	<!-- 记录日志,日志保存到文件中 -->
	<record name="${build.output.log}" append="no"/>

	<record name="${build.output.log.verbose}" append="no" loglevel="verbose"/>

	<target name="total" depends="zip,check-deploy" description="构建完成">
		<echo>${build.output.log.datetime}构建完成!</echo>
	</target>
	
	<target name="check-deploy" depends="deploy" description="测试部署">
		<waitfor maxwait="30" maxwaitunit="second" timeoutproperty="server.missing">
			<http url="${application.url}"/>
		</waitfor>
		<echo>${build.output.log.datetime}测试服务部署${application.url}</echo>
		<fail if="server.missing">${build.output.log.datetime}服务部署失败,未找到指定服务${application.url}</fail>
	</target>
	
	<target name="deploy" depends="war" description="部署">
		<copy file="${build.output.dir}/${project.name}-${project.version}.war"
			todir="${server.address}"
			overwrite="true"/>
		<echo>${build.output.log.datetime}部署完成!</echo>
	</target>
	
	<target name="undeploy" description="解除部署">
		<delete>
			<fileset dir="${server.address}">
				<include name="diary*.war"/>
				<include name="diary*/**/*"/>
			</fileset>
		</delete>
		<echo>${build.output.log.datetime}解除部署完成!</echo>
	</target>
	
	<target name="war" depends="createjar,javadoc" description="生成War">
		<war destfile="${build.output.dir}/${project.name}-${project.version}.war" webxml="${webinf.dir}/web.xml" duplicate="fail">
		  <fileset file="${web.dir}/*.jsp"/>
		  <lib dir="${lib.dir}">
		  	<include name="commons-lang-2.4.jar"/>
		  </lib>
		  <classes dir="${build.dir}">
		  	<include name="diary/**/*"/>
		  	<include name="${build.dir}/test.property"/>
		  </classes>
		</war>
		<echo>${build.output.log.datetime}生成War完成!</echo>
	</target>

	<target name="zip" depends="createjar,javadoc" description="生成Zip">
		<zip destfile="${build.output.dir}/${project.name}-core-${project.version}.zip" duplicate="preserve">
			 <zipfileset dir="${build.output.dir}/docs" prefix="docs"/>
			 <zipfileset dir="${build.output.dir}/requires" prefix="requires"/>
			 <zipfileset file="${build.output.dir}/*.jar"/>
		</zip>
		<echo>${build.output.log.datetime}生成Zip完成!</echo>
	</target>

	<target name="createjar" depends="test" description="生成Jar">
		<manifest file="${build.output.dir}/MANIFEST.MF" encoding="utf-8">
			<attribute name="Built-By" value="${user.name}"/>
			<section name="${project.name}">
				<attribute name="Implementation-Title" value="${project.name}"/>
				<attribute name="Implementation-Version" value="${project.version}"/>
			</section>
		</manifest>
		<jar destfile="${build.output.dir}/${project.name}-core-${project.version}.jar" duplicate="preserve" compress="false" manifestencoding="utf-8" manifest="${build.output.dir}/MANIFEST.MF">
			<fileset dir="${build.dir}">
				<exclude name="test/**/*"/>
				<exclude name="test"/>
				<exclude name="checkstyle_checks.xml"/>
				<exclude name="checkstyle-frames.xsl"/>
				<exclude name="checkstyletask.properties"/>
				<exclude name="sun_checks.xml"/>
				<exclude name="checkstyle_checks.xml"/>
				<exclude name="base.properties"/>
			</fileset>
		</jar>
		<copy todir="${build.output.requires.dir}">
			<fileset refid="compile.jar"/>
		</copy>
		<echo>${build.output.log.datetime}生成Jar完成!</echo>
	</target>

	<target name="javadoc" depends="test" description="生成JavaDoc">  
        <javadoc  
            sourcepath="${src.dir}"  
            destdir="${build.output.doc.dir}"  
            packagenames="diary.*"  
            use="true"  
            version="true"  
            windowtitle="${project.name}"  
            failonerror="true">  
            <classpath refid="compile.classpath"/>  
        </javadoc> 
		<echo>${build.output.log.datetime}生成JavaDoc完成,详情可查看${build.output.doc.dir}/index.html!</echo>
    </target>

	<target name="test" depends="compilesrc,compiletest" description="批量测试,并生成html">  
        <junit printsummary="false" haltonfailure="false" errorProperty="test.failed" failureProperty="test.failed">  
            <classpath refid="test.classpath"/>  
            <formatter type="brief" usefile="false"/>  
            <formatter type="xml"/>  
			<!-- 在testcase定义的情况下,单独测试testcase -->
            <test name="${testcase}" todir="${build.output.test.data.dir}" if="testcase"/>  
			<!-- 批量测试 -->
            <batchtest todir="${build.output.test.data.dir}" unless="testcase">  
                <fileset dir="${build.dir}">  
                    <include name="**/*Test.class"/>  
                </fileset>  
            </batchtest>  
        </junit>  
        <junitreport todir="${build.output.test.data.dir}">  
            <fileset dir="${build.output.test.data.dir}">  
                <include name="TEST-*.xml"/>  
            </fileset>  
            <report format="frames" todir="${build.output.test.dir}"/>  
        </junitreport>  
        <fail if="test.failed">  
            ${build.output.log.datetime}批量测试,并生成html失败,详细可查看${build.output.test.dir}/index.html  
        </fail>  
        <echo>${build.output.log.datetime}批量测试,并生成html完成,详细可查看${build.output.test.dir}/index.html!</echo>  
    </target> 

	<target name="compiletest" depends="copytest,compilesrc" description="编译测试代码文件">
		<javac srcdir="${test.dir}" destdir="${build.dir}" includeAntRuntime="false" encoding="UTF-8">
			<include name="**/*.java"/>
			<classpath refid="test.classpath"/>
		</javac>
		<echo>${build.output.log.datetime}编译测试代码文件完成!</echo>
	</target>

	<target name="copytest" depends="init" description="复制测试代码资源文件到编译目录">
		<fileset dir="${test.dir}">
			<exclude name="**/*.java"/>
		</fileset>
		<echo>${build.output.log.datetime}复制测试代码资源文件到编译目录完成!</echo>
	</target>

	<target name="compilesrc" depends="checkstyle,copysrc" description="编译源代码文件">
		<javac srcdir="${src.dir}" destdir="${build.dir}" includeAntRuntime="false" encoding="UTF-8">
			<include name="**/*.java"/>
			<classpath refid="compile.classpath"/>
		</javac>
		<echo>${build.output.log.datetime}编译源代码文件完成!</echo>
	</target>

	<target name="copysrc" depends="init" description="复制源代码资源文件到编译目录">
		<copy todir="${build.dir}" includeemptydirs="false">
			<fileset dir="${src.dir}">
				<exclude name="**/*.java"/>
			</fileset>
		</copy>
		<echo>${build.output.log.datetime}复制源代码资源文件到编译目录完成!</echo>
	</target>

	<target name="checkstyle" depends="init" description="用Checkstyle校验源代码">
		<taskdef name="checkstyle"  classname="com.puppycrawl.tools.checkstyle.CheckStyleTask" classpathref="checkstyle.classpath"/> 
        <checkstyle    
            failOnViolation="false"      
            failureProperty="checkstyle.failed"     
            config="${src.dir}/sun_checks.xml">     
            <fileset dir="${src.dir}" includes="**/*.java"/>      
            <formatter type="plain"/>      
            <formatter type="xml" toFile="${build.output.checkstyle.dir}/checkstyle_report.xml"/>      
        </checkstyle>
		<xslt style="${checkstyle.xsl}"      
            in="${build.output.checkstyle.dir}/checkstyle_report.xml"      
            out="${build.output.checkstyle.dir}/checkstyle_report.html">    
        </xslt>
		<echo>${build.output.log.datetime}用Checkstyle校验源代码完成,详细信息查看${build.output.checkstyle.dir}/checkstyle_report.html!</echo>
    </target>

	<target name="init" depends="clean,cleanoutput" description="创建输出目录">
		<mkdir dir="${build.dir}"/>
		<mkdir dir="${build.output.dir}"/>
		<mkdir dir="${build.output.doc.dir}"/>
		<mkdir dir="${build.output.test.dir}"/>
		<mkdir dir="${build.output.test.data.dir}"/>
		<mkdir dir="${build.output.checkstyle.dir}"/>
		<copy todir="${build.output.checkstyle.dir}" overwrite="true">
			<fileset dir="${src.dir}">
				<include name="checkstyle-frames.xsl"/>
				<include name="checkstyle_checks.xml"/>
			</fileset>
			<filterset>
				<filter token="output.dir" value="${build.output.checkstyle.dir}"/>
			</filterset>
		</copy>
		<echo>${build.output.log.datetime}输出目录创建完成!</echo>
	</target>

	<target name="clean" description="清理编译目录">
		<delete includeemptydirs="true">
			<fileset dir="${build.dir}">
				<include name="**/*"/>
			</fileset>
		</delete>
		<echo>${build.output.log.datetime}编译目录清理完成!</echo>
	</target>

	<target name="cleanoutput" description="清理输出目录">		
		<delete includeemptydirs="true">
			<fileset dir="${build.output}">
				<exclude name="output*.log"/>
			</fileset>
		</delete>
		<echo>${build.output.log.datetime}输出目录清理完成!</echo>
	</target>
	
</project>

 

分享到:
评论

相关推荐

    jmeter+ant+Jenkins搭建接口自动化测试

    将JMeter和Ant整合到Jenkins中,可以实现接口自动化测试的一键自动执行。 - **安装Jenkins**:首先需要在服务器或本地环境中安装Jenkins。 - **配置Jenkins Job**:在Jenkins中创建一个新的Job,并配置其构建触发器...

    Jmeter+Ant+Jenkins接口自动化测试平台

    本文将详细介绍如何利用JMeter、Ant和Jenkins构建一个高效的接口自动化测试平台,以提升测试效率,确保系统的稳定性和可靠性。 一、JMeter:性能测试利器 JMeter是一款开源的Java应用,专门用于压力测试和性能测试...

    基于Jmeter+Ant+SVN+Jenkins实现接口自动化测试

    本话题将详细介绍如何利用JMeter、Ant、SVN和Jenkins这四款工具来构建一个完整的接口自动化测试流程。 首先,Apache JMeter是一款强大的性能测试工具,它主要用于测试Web应用,包括接口测试。通过JMeter,我们可以...

    搭建Jenkins+Jmeter+Ant自动化集成环境(修订2210202).docx

    ### Jenkins、JMeter与Ant整合 1. 将JMeter的`ant-jmeter-1.1.1.jar`复制到Ant的lib目录,使得Ant能识别JMeter的任务。 2. 创建一个用于存储测试结果的目录结构,例如`D:\JmeterTest\resultLog`,包含html和jtl子...

    jenkins自动化部署持续交付演示ppt

    它的优点包括:易于安装和使用,支持多种版本控制系统,能自动检测源代码的变更,发送构建结果通知,并能与多种构建工具(如Ant、Maven)集成。虽然Hudson的社区活跃度不如Jenkins,但在某些情况下,它仍然是一个...

    JMeter ant Jenkins接口自动化持续集成框架初探

    ant是Apache软件基金会的一个Java库,用于自动化程序的构建过程,它是JMeter中执行测试计划的推荐方法。通过ant脚本,可以自动化地完成测试任务的编译、部署、运行和报告生成等过程,这对于持续集成框架来说至关重要...

    jenkins-svn+ant插件(含依赖).zip

    《Jenkins、SVN与Ant:构建自动化利器的整合与应用》 在现代软件开发流程中,持续集成(Continuous Integration, CI)扮演着至关重要的角色,而Jenkins作为一款广泛应用的开源CI工具,极大地提升了团队协作效率。在...

    基于Jenkins的PHP自动构建

    Jenkins作为一个开源的自动化服务器,广泛用于自动化各种任务,如构建、测试和部署软件。本文将介绍如何利用Jenkins进行PHP项目的自动构建,包括Jenkins的安装、配置以及与PHP相关的自动化构建工具的使用。 首先,...

    Jmeter+Jenkins+maven接口自动化集成.rar

    在接口自动化测试中,Maven可以帮助我们管理测试所需的依赖库,构建测试环境,并且可以与Jenkins结合,通过命令行触发构建和测试流程,使得整个过程更加规范化和自动化。 集成这三者的过程大致如下: 1. **配置...

    jenkins-2.190.3.zip

    【Jenkins 2.190.3 安装与Python+Ant+Jenkins框架集成】 Jenkins是一款开源的持续集成工具,...Python Plugin和Ant Plugin是关键,它们使得Jenkins能够执行Python脚本和Ant构建任务,实现接口自动化测试的持续集成。

    jenkins+jmeter+ant集成用到的插件

    在构建高效的性能测试和持续集成流程中,Jenkins、JMeter和Ant的集成扮演着至关重要的角色。这些工具的组合可以有效地实现自动化测试和监控,从而提升软件开发的效率和质量。以下将详细介绍这些工具以及它们集成时所...

    自动化测试系列五 ANT

    然而,如果这些文件是测试数据的一部分,或者包含测试脚本,那么它们可能需要被解压缩并整合到ANT的构建流程中,以便在测试过程中使用。 总结来说,ANT是一个强大的工具,它在自动化测试中的作用不可忽视。通过配置...

    Jmeter+ant+jenkins接口层性能与自动化测试

    4、Jenkins 构建自动化平台、Jenkins 安装以及功能介绍、jenkins+ant+jmeter **整合,邮件服务通知设置。 5、本课程注重实践每一个知识点都有相对应的实例,本书覆盖的实例多达上百个,提高学员的动手能 力和解决...

    ant学习之集成svn

    标题“ant学习之集成svn”涉及的是在Java项目中使用...总的来说,"ant学习之集成svn"是一个关于如何在Java开发环境中利用Apache Ant工具与Subversion进行有效协作的主题,帮助开发者实现源代码的版本控制和构建自动化。

    junit与ant的整合(非常重要)

    要将JUnit与Ant整合,首先需要在项目的build.xml文件中引入JUnit库。在标签内添加标签,指定JUnit的任务定义: ```xml &lt;taskdef resource="net/sf/antcontrib/antlib.xml"&gt; &lt;pathelement location="path/to/ant-...

    jenkins 持续集成

    整合Jenkins与SonarQube主要包括以下步骤: 1. 在Jenkins服务器上安装SonarQube Scanner插件。 2. 配置SonarQube服务器的连接信息,包括URL、认证凭据等。 3. 在Jenkins Job中添加构建步骤,运行SonarQube Scanner...

    Ant+JMeter后台自动化测试

    2. **创建构建任务**:在Jenkins中创建一个新的构建任务,配置Ant目标以执行JMeter测试。 3. **配置测试计划**:在构建任务中指定JMeter测试计划的位置。 4. **设置触发器**:根据需求设置构建触发器,例如每次代码...

Global site tag (gtag.js) - Google Analytics