一个简化的自动化构建过程包括:
- 从存储库取得最新的代码
- 构建代码
- 记录构建版本号
- 运行单元测试
- 上传部署版本
- 发送电子邮件
- 从存储库取得最新的代码
<cvs cvsRoot=":pserver:anoncvs@cvs.apache.org:/home/cvspublic"
<cvs dest="${ws.dir}" command="update"/> <!-- 执行cvs update -->
package="moduleName"
dest="${ws.dir}"
/> <!-- 执行cvs check out--> - 构建代码
执行自定义Ant构建任务。 - 记录构建版本号
<buildnumber file="mybuild.number"/>
或<target name="baseline" description="Record build information">
<!-- The name of the file that holds the build information. If no such file exists, a new
one gets created. -->
<propertyfile file="${destination.dir}/build.info">
<!-- Initial build number is 0001. Then, any subsequent build increments
this number by one each time. -->
<entry default="0001" key="build.number" operation="+" pattern="0000" type="int" />
<!-- Records the current time to the same file. -->
<entry default="now" key="build.time" pattern=" yyyy.MM.dd-HH:mm" type="date" />
</propertyfile>
</target> - 运行单元测试
<!-- ========================================
target: auto test all test case and output report file
===================================== -->
<target name="junit and report" depends="test init, all compile">
<junit printsummary="on" fork="true" showoutput="true">
<classpath>
<fileset dir="lib" includes="**/*.jar" />
<pathelement path="${output.folder}" />
<pathelement path="${basedir}/src/resource" />
</classpath>
<formatter type="xml" />
<batchtest todir="${report.folder}">
<fileset dir="${output.folder}">
<include name="**/*Test.*" />
</fileset>
</batchtest>
</junit>
<junitreport todir="${report.folder}">
<fileset dir="${report.folder}">
<include name="TEST-*.xml" />
</fileset>
<report format="noframes" todir="${ report.folder}" />
</junitreport>
</target> - 上传部署版本
<target name="uploadbuild" description="Upload build to an FTP server">
<!-- Upload everything under the destination.dir to the FTP server. -->
<ftp server="${ftp.hostname}" remotedir="/" userid="${ftp.username}"
password="${ ftp.userpassword}" separator="\" verbose="yes" binary="yes">
<fileset dir="${destination.dir}">
<include name="**/*.*" />
</fileset>
</ftp>
</target> - 发送电子邮件
<target name="notifyteam" description="Notify testing team of the new build">
需要javaMail.jar
<!-- Read build information from the build.info file. -->
<property file="${destination.dir}/build.info" />
<!-- Send a mail to the testing team. -->
<mail mailhost="${smtp.hostname}" mailport="${smtp.hostport}"
user="${mail.user}"
password="${mail.password}"
subject="Test build #${ build.number}"
from="${smtp.from}" tolist="${smtp.tolist}">
<message>The build #${build.number} is now available for testing.</message>
</mail>
</target>
没有评论:
发表评论