Jenkins安装
下载jenkins.war包,运行java -jar jenkins.war,即可访问http://localhost:8080/访问jenkins。
或者将jenkins.war包放在Tomcat的Webapp下,启动Tomcat,访问http://localhost:8080/jenkins/。
本例产用后者。
1. 在首页选择系统管理,再右侧页面中选择管理插件。
在可选插件中选择要安装的插件,下表为本次测试中已安装的插件,有些为默认已安装的插件。
插件
|
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>
本文介绍如何使用Jenkins进行持续集成,包括安装Jenkins、配置插件、创建JOB并进行构建等过程。同时展示了如何集成Ant、Checkstyle、JUnit、Javadoc及部署应用到Tomcat等操作。
767

被折叠的 条评论
为什么被折叠?



