持续集成 .Net手册

持续集成 .Net手册

一、概念

Martin Fowler的文章:Continuous Integration  中文翻译:持续集成

二、工具

传统工具:VisualStudio.Net,VisualSourceSafe,Rational ClearCase

自动编译工具:NAntNAntContrib

回归测试工具:NUnit

代码检查工具:FxCop

持续集成工具:CruiseControl.Net

三、步骤

  • CruiseControl.Net监控远程版本控制系统的变化

  • 变化发生时CruiseControl.Net调用编译工具进行编译(NAnt或VisualStudio.Net)

  • 编译成功后调用NUnit进行回归测试

  • 编译成功后调用FxCop进行代码检查

  • 完毕后将编译结果、测试结果、代码检查结果发送至开发人员、主管经理,并发布至网站

    图示:

   

    所有这一切都是按照编制好的脚本自动进行的

四、实施示例

目前我们使用的是ClearCase

主控软件为CruiseControl.Net,其脚本文件为ccnet.config

  • 配置远程版本控制系统

- < sourcecontrol type =" clearCase ">
  < viewPath > D:/cc_view/USE_TECH_DEPT/Platform/Nucleus/2产品开发/2实现/Nucleus1.0/Source </ viewPath >
  < useLabel > false </ useLabel >
  </ sourcecontrol >
  • 配置编译工具

- < build type =" nant ">
  < executable > F:/software/Agile.Net/nant-0.85-nightly/bin/nant.exe </ executable >
  < baseDirectory > F:/software/Agile.Net/nant-0.85-nightly/bin </ baseDirectory >
  < buildFile > Y:/nucleus.build </ buildFile >
  < logger > NAnt.Core.XmlLogger </ logger >
- < targetList >
  < target > build </ target >
  < target > fxcop </ target >
  </ targetList >
  </ build >
  • 配置测试用例

- < tasks >
- < nunit >
  < path > D:/Program Files/NUnit 2.2/bin/nunit-console.exe </ path >
- < assemblies >
  < assembly > Y:/NewPDObject/TestNewPDObject/bin/Debug/TestNewPDObject.exe </ assembly >
  </ assemblies >
  </ nunit >
  </ tasks >
  • 配置报告形式
< publishers >
- < xmllogger >
  < logDir > ../web/log </ logDir >
- < mergeFiles >
  < file > Y:/nucleus.xml </ file >
  </ mergeFiles >
  </ xmllogger >
- < email from =" ajaxchelsea@163.com " mailhost =" 163.com " includeDetails =" TRUE ">
  < projectUrl >http:// ajaxchelsea/ccnetweb </ projectUrl >
- < users >
  < user name =" BuildGuru " group =" buildmaster " address =" ajaxchelsea@163.com " />
  < user name =" chelsea " group =" developers " address =" chelsea@chelseafc.com " />
  < user name =" ajax " group =" developers " address =" ajax@ajaxfc.com " />
  </ users >
- < groups >
  < group name =" developers " notification =" always " />
  < group name =" buildmaster " notification =" always " />
  </ groups >
  </ email >
  </ publishers >
  • 其中CruiseControl.Net没有提供代码检查工具FxCop的支持,其文档建议使用NAnt的<exec>任务来调用FxCop,直到出现<fxcop>的Task,因此,需要配置NAnt的脚本文件:
- < target name =" fxcop " depends =" build ">
  < exec program =" D:/Program Files/Microsoft FxCop 1.30/fxcopcmd.exe " commandline =" /p:Y:/nucleus.fxcop /o:Y:/nucleus.xml " failonerror =" false " />
  </ target >

五、几点提示

  • CruiseControl.Net会自动根据本地ClearCase的View监控远程VOB
  • 其实除了监控远程版本控制系统外其它的任务都可以由NAnt来完成,CCNet只负责监控变化并调用NAnt即可
  • 可以直接为CCNet配置VisualStudio.Net解决方案"<build type="devenv" solutionfile="D:/dev/MyProject/MyProject.sln" configuration="debug" /> ",但这样就无法配置FxCop了,至少目前如此;
  • ccnetservice.exe.config中有一句“<add key="ccnet.config" value="C:/Downloads/TestData/ccnet.config" /> ”应该是配置ccnet.config的路径,但现在好像不管用,还得将ccnet.config放在server目录下 
  • 最好避免中文路径,否则就需要手工为几个Xml格式的文件,如.csproj等加入编码方式“<?xml version="1.0" encoding="UTF-8" ?>,或者将中文路径映射为虚拟硬盘:“subst Y: "D:/cc_view/USE_TECH_DEPT/Platform/Nucleus/2产品开发/2实现/Nucleus1.0/Source"”
  • NUnit有VisualStudio.Net插件NUnitAddin,FxCop等亦可以配置为VisualStudio外部工具,推荐使用
  • 各种工具的安装、使用,在各自的文档里都非常详细,网上亦有无数资源

六、参考资料

 ========================================================================

 

持续集成 Java手册

一、概念

Martin Fowler的文章:Continuous Integration  中文翻译:持续集成

二、工具

传统工具:JBuilder,VisualSourceSafe,Rational ClearCase

自动编译工具:Ant

回归测试工具:JUnit

代码检查工具:CheckStyle

持续集成工具:CruiseControl

三、步骤

  • CruiseControl监控远程版本控制系统的变化

  • 变化发生时CruiseControl调用编译工具进行编译(Ant等)

  • 编译成功后调用JUnit进行回归测试

  • 编译成功后调用CheckStyle进行代码检查

  • 打包,部署,更新版本控制系统

  • 完毕后将编译结果、测试结果、代码检查结果发送至开发人员、主管经理,并发布至网站,甚至报警器

    所有这一切都是按照编制好的脚本自动进行的

四、实施示例

目前我们使用的是ClearCase,主控软件为CruiseControl,其脚本文件为cccc.xml

  • 配置远程版本控制系统

<modificationset quietperiod="60">

  <clearcase branch="main" viewpath="D:/cc_view/chelseafc/Nucleus2.0/Port" recursive="true" />

</modificationset>

  • 配置编译工具

<schedule interval="60">

  <ant antscript="C:/Java/JBuilder2005/thirdparty/ant/bin/ant.bat" buildfile="D:/cc_view/chelseafc/Nucleus2.0/Port/clearcase-build.xml" target="cleanbuild" multiple="1" />

</schedule>

  • 配置测试用例(在ant的配置文件中)

<target name="test" depends="init" description="Run unit tests">

  <delete dir="${junit.results}" />

  <mkdir dir="${junit.results}" />

  <junit fork="yes" haltonfailure="yes">

  <classpath refid="project.class.path" />

  <formatter type="plain" usefile="false" />

  <formatter type="xml" />

  <batchtest todir="${junit.results}">

  <fileset dir="${build.dir}" includes="**/*TestCase.class" />

  <fileset dir="${build.dir}" includes="**/*TestSuite.class" />

  </batchtest>

  </junit>

</target>

  • 配置报告形式

<publishers>

  <currentbuildstatuspublisher file="currentbuild.txt" />

  <htmlemail mailhost="mail.chelseafc.com.cn" returnaddress="workflow_engine@chelseafc.com.cn" subjectprefix="ContinuousIntegration:" buildresultsurl="http://chelsea:8044/cruisecontrol/buildresults" spamwhilebroken="true" xsldir="F:/software/Agile.Net/cruisecontrol-2.2/reporting/jsp/xsl" css="F:/software/Agile.Net/cruisecontrol-2.2/reporting/jsp/css/cruisecontrol.css" logdir="D:/Tomcat 4.1/webapps/cruisecontrol/samplelogs">

  <always address="chelsea@chelseafc.com.cn" />

  <always address="ajax@chelseafc.com.cn" />

  <map alias="chelsea" address="chelsea@chelseafc.com.cn" />

  </htmlemail>

  </publishers>

  • 其中CruiseControl暂时没有提供代码检查工具的支持,建议使用Ant来调用CheckStyle,示例如下(没有真正运行过):

<target name="web.checkstyle">

  <mkdir dir="${target.temp}/checkstyle" />

  <mkdir dir="${target.web}/checkstyle" />

  <taskdef resource="checkstyletask.properties">

  <classpath>

  <fileset dir="${support.tools}/checkstyle31" includes="**/*.jar"/>

  </classpath>

  </taskdef>

  <copy file="${support.tools}/checkstyle31/custom.xml" overwrite="true" tofile="${target.temp}/checkstyle/custom.xml">

  <filterset>

  <filter token="source.java" value="${basedir}/${source.java}" />

  <filter token="target.checkstyle" value="${basedir}/${target.temp}/checkstyle" />

  </filterset>

  </copy>

  <checkstyle config="${target.temp}/checkstyle/custom.xml" failOnViolation="false">

  <fileset dir="${source.java}/main" includes="**/*.java" />

  <formatter type="plain" />

  <formatter type="xml" toFile="${target.temp}/checkstyle/checkstyle_errors.xml" />

  </checkstyle>

  <style basedir="${target.temp}/checkstyle" destdir="${target.web}/checkstyle" includes="checkstyle_errors.xml" style="${support.tools}/checkstyle31/checkstyle-noframes.xsl" />

  </target>

  • 打包、部署(在ant的配置文件中)

<target name="jar">

<jar jarfile="${dist.dir}/nucleus_engine.jar">

  <fileset dir="${build.dir}" />

</jar>

<jar jarfile="../../M1/Web/lib/service_gateway.jar">

  <fileset dir="${build.dir}" />

</jar>

</target>

<target name="war">

  <ant antfile="build-war.xml" />

</target>

  • check out 版本控制工具中的配置项(在ant的配置文件中)

<target name="checkoutzipfile">

  <cccheckout viewpath="../Release/nucleus2.0.zip" reserved="true" branch="main" />

</target>

  • 压缩zip文件(在ant的配置文件中)

<target name="zip">

  <zip destfile="../Release/nucleus2.0.zip" basedir="../Release/nucleus2.0" />

</target>

  • check in 版本控制工具中的配置项(在ant的配置文件中)

<target name="checkinzipfile">

  <cccheckin viewpath="../Release/nucleus2.0.zip" identical="true" />

</target>

五、几点提示

  • CruiseControl会自动根据本地ClearCase的View监控远程VOB

  • 其实除了监控远程版本控制系统外其它的任务都可以由Ant来完成,CC只负责监控变化并调用Ant即可

  • CruiseControl2.2的<htmlemail>好像无法在jdk5.0下运行,如果需要集成jdk5.0的项目,则需要为Ant的<javac>指定source和target,而CruiseControl2.2依然用jdk1.4启动

  • 可以为cruisecontrol.bat加入启动参数“-port 8055”,这样可以用JMX(http://localhost:8055)来控制cc

  • 最好避免中文路径,否则就需要手工为几个Xml格式的文件,如cc的report Servlet的Web.xml等加入编码方式“<?xml version="1.0" encoding="UTF-8" ?>,或者将中文路径映射为虚拟硬盘:“subst Y: "D:/cc_view/chelsea/Platform/开发/Nucleus2.0/Source"”

  • 中文log无法正常显示时,需要设置CruiseControl配置文件中<log>元素的“encoding”属性,如:

    <log dir="D:/Tomcat 4.1/webapps/cruisecontrol/samplelogs" encoding="utf-8">

      <merge dir="D:/cc_view/chelseafc/Nucleus2.0/Port/test-results" />

    </log>

  • 编译失败后,在下次checkin之前,一般不需要重新编译,这时可设置<project >的“buildafterfailed”属性为false来避免重新编译

  • <htmlemail>的几个属性好像没有缺省设置,虽然文档里说从2.1.7开始有缺省设置,包括xsldir,css,logdir

  • 可使用JBuilder辅助生成ant文件

  • 各种工具的安装、使用,在各自的文档里都非常详细,网上亦有无数资源

六、参考资料

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值