原文链接:URL

 

CruiseControl.NET+MsBuild+MsTest+SVN进行自动构建。

CruiseControl.NET由C#编写,需要.NET Framework运行时的支持(或者Mono),至少需要.NET Framework2.0

 使用CruiseControl.NET可以自动化一下工作

从SVN获取代码

编译代码

代码检查

单元测试

发送邮件

等等

CruiseControl.NET下载地址:http://sourceforge.net/projects/ccnet/files/CruiseControl.NET%20Releases/CruiseControl.NET安装

1.CruiseControl.NET需要安装,安装非常简单,点下一步就行。

安装之后会生成一个windows服务(CruiseControl.NET Server 需要手动启动)

在安装目录下会一个webdashboard网站,需要把这个网站部署到IIS中(如果安装的时候没有部署好的话)

在开始菜单中可以打开CCNET.config文件,CruiseControl.NET Server就是根据这个配置文件来进行自动构建的

CCNET.config默认有如下配置项

[html] view plaincopy在CODE上查看代码片派生到我的代码片
 
  1. <triggers>  
  2.       <!-- 定时检查SVN代码是否更改,如果有更改就执行下面的任务-->  
  3.       <intervalTrigger  
  4.                name="continuous"  
  5.                seconds="30"  
  6.                buildCondition="IfModificationExists"  
  7.                initialSeconds="5"/>  
  8.     </triggers>  


 

2.从SVN获取代码(当然CruiseControl.NET还支持其他很多源码管理工具)

首先需要安装SVN客户端(使用SVN在本机进行迁入迁出)

svn客户端必须使用svn.exe,不能使用TortoiseSVN客户端。

svn下载地址:http://sourceforge.net/projects/ccnet/files/latest/download?source=files

在CCNET.Config中进行配置

[html] view plaincopy在CODE上查看代码片派生到我的代码片
 
  1. <!--SVN配置-->  
  2.     <sourcecontrol   type="svn" >  
  3.           <trunkUrl>file:///D:/chenb/SVN/Trunk/CCNET2</trunkUrl>  
[html] view plaincopy在CODE上查看代码片派生到我的代码片
 
  1. <executable>C:\Program Files\svn-win32-1.8.3\bin\svn.exe</executable>   
[html] view plaincopy在CODE上查看代码片派生到我的代码片
 
  1. <workingDirectory>D:\CCNET2\CCNET2</workingDirectory>  
  2. cecontrol>   

trunkUrl是svn的工作库,如果是使用svn服务端,配置就有点不一样

workingDirectory是本机放源码的文件夹

3.配置msbuild,编译代码(当然可以使用其他的,比如VS自带的编译)

安装.NET之后默认安装了msbuild

配置如下:

[html] view plaincopy在CODE上查看代码片派生到我的代码片
 
  1. <!--编译项目-->  
  2.       <msbuild>  
  3.         <executable>C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe</executable>  
  4.         <workingDirectory>D:\CCNET2\CCNET2</workingDirectory>  
  5.         <projectFile>CCNET2.sln</projectFile>  
  6.         <logger>C:\Program Files\CruiseControl.NET\server\ThoughtWorks.CruiseControl.MSBuild.dll</logger>  
  7.         <targets>Build</targets>  
  8.         <timeout>900</timeout>  
  9.         <buildArgs>/p:Configuration=Debug /v:diag</buildArgs>  
  10.       </msbuild>  

executable:指定msbuild的路径

workingDirectory:项目的路径

projectFile:项目名称

BuildArgs:编译参数(如Debug、Release)

 

4.使用Fxcop进行代码检测

安装VS之后,在开始菜单中会看到Fxcop,点击之后会提示安装。

打开Fxcop如下:

可以在My Fxcop Project上右键添加要进行代码检查了程序集。在Rules可以选择要应用的规则。点击保存之后会生成一个.FxCop后缀的文件。

编写一个批处理,来执行Fxcop文件

[plain] view plaincopy在CODE上查看代码片派生到我的代码片
 
  1. cd C:\Program Files\Microsoft FxCop 1.36  
  2. FxCopCmd /project:D:\CCNET2\1.FxCop /out:D:\CCNET2\DailyBuild.Fxcop.xml /q /gac  

 

CCNET.config中配置如下:

[html] view plaincopy在CODE上查看代码片派生到我的代码片
 
  1. <!--执行代码检查-->  
  2.       <exec executable="D:\CCNET2\fxcop.bat" />  


 

5.使用mstest进行单元测试

CCNET.config配置如下:

[html] view plaincopy在CODE上查看代码片派生到我的代码片
 
  1. <!--执行单元测试-->  
  2.       <exec>  
  3.         <executable>c:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\mstest.exe</executable>  
  4.         <baseDirectory>D:\CCNET2\CCNET2</baseDirectory>  
  5.         <buildArgs>/testcontainer:TestProject\bin\Debug\TestProject.dll /resultsfile:TestResults\mstest-results.xml</buildArgs>  
  6.         <buildTimeoutSeconds>300</buildTimeoutSeconds>  
  7.       </exec>  

executable:mstest.exe路径(安装VS自带)

buildArgs:参数,/testcontainer:单元测试项目程序集(可以包含多个)  /resultsfile:测试结果文件

 

6.发送编译、测试结果邮件

CCNET.config配置如下:

[html] view plaincopy在CODE上查看代码片派生到我的代码片
 
  1. <!--发送邮件-->  
  2.      <email mailport="25" includeDetails="true" mailhostUsername="cheng@126.com" mailhostPassword="12345678" useSSL="FALSE">  
  3.        <from>cheng@126.com</from>  
  4.        <mailhost>smtp.126.com</mailhost>  
  5.        <users>  
  6.          <user name="cheng" group="buildmaster" address="cheng@gmail.com" />  
  7.        </users>  
  8.   
  9.        <groups>  
  10.          <group name="developers">  
  11.            <notifications>  
  12.              <notificationType>Failed</notificationType>  
  13.              <notificationType>Fixed</notificationType>  
  14.            </notifications>  
  15.          </group>  
  16.          <group name="buildmaster">  
  17.            <notifications>  
  18.              <notificationType>Always</notificationType>  
  19.            </notifications>  
  20.          </group>  
  21.        </groups>  
  22.         
  23.        <!--<converters>  
  24.          <regexConverter find="$" replace="@gmail.com" />  
  25.        </converters>-->  
  26.        <xslFiles>  
  27.            <file>xsl\header.xsl</file>  
  28.            <file>xsl\compile.xsl</file>  
  29.            <file>xsl\unittests.xsl</file>  
  30.            <file>xsl\modifications.xsl</file>  
  31.            <file>xsl\MsTestReport2010.xsl</file>  
  32.            <file>xsl\fxcop-summary_1_36.xsl</file>  
  33.        </xslFiles>  
  34.   
  35.        <!--失败的邮件标题-->  
  36.        <subjectSettings>  
  37.            <subject buildResult="StillBroken" value="Build is still broken for {CCNetProject}" />  
  38.        </subjectSettings>  
  39.        <attachments>  
  40.             <file>D:\CCNET2\CCNET2\TestResults\mstest-results.xml</file>  
  41.        </attachments>  
  42.   
  43.      </email>  
  44.    </publishers>  

上面配置的是使用126邮箱发送邮件

xslFiles:配置发送哪些测试结果。

subjectSettings:配置但编译成功、失败等,邮件的标题。buildResult有固定的值。

attachments:给邮件添加附件

 

完整CCNET.config如下:

[html] view plaincopy在CODE上查看代码片派生到我的代码片
 
  1. <cruisecontrol xmlns:cb="urn:ccnet.config.builder">  
  2.   <!-- This is your CruiseControl.NET Server Configuration file. Add your projects below! -->  
  3.   
  4. <!--项目名称、项目描述-->  
  5.   <project name="CCNET2"  
  6.            description="demoproject showing a small config">  
  7.   
  8.     <triggers>  
  9.       <!-- 定时检查SVN代码是否更改,如果有更改就执行下面的任务-->  
  10.       <intervalTrigger  
  11.                name="continuous"  
  12.                seconds="30"  
  13.                buildCondition="IfModificationExists"  
  14.                initialSeconds="5"/>  
  15.     </triggers>  
  16.   
  17.   <!--SVN配置-->  
  18.     <sourcecontrol   type="svn" >  
  19.     <trunkUrl>file:///D:/chenb/SVN/Trunk/CCNET2</trunkUrl>  
  20.     <workingDirectory>D:\CCNET2\CCNET2</workingDirectory>  
  21.     </sourcecontrol>   
  22.       
  23.     <!--任务列表-->  
  24.     <tasks>  
  25.         
  26.       <!-- 如果想让任务失败,请ping未知的主机 -->  
  27.       <exec>  
  28.         <executable>ping.exe</executable>  
  29.         <buildArgs>localhost</buildArgs>  
  30.         <buildTimeoutSeconds>15</buildTimeoutSeconds>  
  31.         <description>Pinging a server</description>  
  32.       </exec>  
  33.   
  34.       <!--编译项目-->  
  35.       <msbuild>  
  36.         <executable>C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe</executable>  
  37.         <workingDirectory>D:\CCNET2\CCNET2</workingDirectory>  
  38.         <projectFile>CCNET2.sln</projectFile>  
  39.         <logger>C:\Program Files\CruiseControl.NET\server\ThoughtWorks.CruiseControl.MSBuild.dll</logger>  
  40.         <targets>Build</targets>  
  41.         <timeout>900</timeout>  
  42.         <buildArgs>/p:Configuration=Debug /v:diag</buildArgs>  
  43.       </msbuild>  
  44.   
  45.       
  46.       <!--执行代码检查-->  
  47.       <exec executable="D:\CCNET2\fxcop.bat" />  
  48.         
  49.       <!--删除单元测试结果文件,否则不会创建新的结果文件-->  
  50.       <exec executable="D:\CCNET2\delmstestresult.bat" />  
  51.        
  52.       <!--执行单元测试-->  
  53.       <exec>  
  54.         <executable>c:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\mstest.exe</executable>  
  55.         <baseDirectory>D:\CCNET2\CCNET2</baseDirectory>  
  56.         <buildArgs>/testcontainer:TestProject\bin\Debug\TestProject.dll /resultsfile:TestResults\mstest-results.xml</buildArgs>  
  57.         <buildTimeoutSeconds>300</buildTimeoutSeconds>  
  58.       </exec>  
  59.   
  60.       <!--合并xml文件-->  
  61.       <merge>  
  62.         <files>  
  63.           <file>D:\CCNET2\*.xml</file>  
  64.           <file>D:\CCNET2\CCNET2\TestResults\mstest-results.xml</file>  
  65.         </files>  
  66.       </merge>  
  67.     </tasks>  
  68.       
  69.     <publishers>  
  70.       <!--记录日志-->  
  71.       <xmllogger />  
  72.         
  73.       <!--保留多少日志文件-->  
  74.       <artifactcleanup cleanUpMethod="KeepLastXBuilds"  
  75.                        cleanUpValue="50" />  
  76.         
  77.       <!--发送邮件-->  
  78.       <email mailport="25" includeDetails="true" mailhostUsername="cheng@126.com" mailhostPassword="12345678" useSSL="FALSE">  
  79.         <from>cheng@126.com</from>  
  80.         <mailhost>smtp.126.com</mailhost>  
  81.         <users>  
  82.           <user name="cheng" group="buildmaster" address="cheng@gmail.com" />  
  83.         </users>  
  84.   
  85.         <groups>  
  86.           <group name="developers">  
  87.             <notifications>  
  88.               <notificationType>Failed</notificationType>  
  89.               <notificationType>Fixed</notificationType>  
  90.             </notifications>  
  91.           </group>  
  92.           <group name="buildmaster">  
  93.             <notifications>  
  94.               <notificationType>Always</notificationType>  
  95.             </notifications>  
  96.           </group>  
  97.         </groups>  
  98.          
  99.         <!--<converters>  
  100.           <regexConverter find="$" replace="@gmail.com" />  
  101.         </converters>-->  
  102.         <xslFiles>  
  103.             <file>xsl\header.xsl</file>  
  104.             <file>xsl\compile.xsl</file>  
  105.             <file>xsl\unittests.xsl</file>  
  106.             <file>xsl\modifications.xsl</file>  
  107.             <file>xsl\MsTestReport2010.xsl</file>  
  108.             <file>xsl\fxcop-summary_1_36.xsl</file>  
  109.         </xslFiles>  
  110.   
  111.         <!--失败的邮件标题-->  
  112.         <subjectSettings>  
  113.             <subject buildResult="StillBroken" value="Build is still broken for {CCNetProject}" />  
  114.         </subjectSettings>  
  115.         <attachments>  
  116.              <file>D:\CCNET2\CCNET2\TestResults\mstest-results.xml</file>  
  117.         </attachments>  
  118.   
  119.       </email>  
  120.     </publishers>  
  121.   
  122.   </project>  
  123.   
  124. </cruisecontrol>  


 delmstestresult.bat内容如下:

[plain] view plaincopy在CODE上查看代码片派生到我的代码片
 
  1. d:  
  2. cd d:\CCNET2\CCNET2\TestResults  
  3. if exist mstest-results.xml (del d:\CCNET2\CCNET2\TestResults\mstest-results.xml)  


 问题:

1、svn: E230001: Server SSL certificate verification failed: certificate issued for a different hostname

解决方法:

运行certmgr.msc,把证书添加到个人证书。

让CruiseControl.NET Server服务使用当前用户运行

 posted on 2014-06-30 14:29  Lucien.Bao  阅读(1396)  评论(3)    收藏  举报