持续集成(一)

一、What

持续集成:一种软件开发实践,通过自动化构建(build, ut, deploy)进行验证,以尽快发现集成bug

                  Mark:copied from web

 

二、Why

Ø减少集成风险,尽早发现问题
Ø增强项目可见性
Ø减少手工重复过程,安装包随时有
Ø促进提交秩序 + 生产率。(coverage percent & bug 多了,owner hold不住啊)
 

三、Where

大的Project,周期长的Project频繁发布的Project…总之,想要就干。

四、How

a)使用组件

•CruiseControl.Net 1.8
•MsBuild
•Nunit 2.6
•OpenCover 4.0.724
•ReportGenerator 1.5.0.0
•VisualSVN 1.7.6

以上组件all are free。Perfect。

b)其他可选组件

•CCTray, 客户端组件,据说功能比dashboard多,but I thought web is nicer。
•FxCop,免费的代码规范检查工具
•Siman,商业的代码冗余检查工具
 
 可替代组件
•Nant,很popular的一个组件,不清楚VS MsBuild有啥优点,起码有.net就有MsBuild。
•Ncover,most popular on .net platform, but it have to paid.(吐槽一下,3.1不支持.net 4.0。)还有其他的dotCover, partCover..
•MsTest, 现与Nunit不分轩轾。

c)Configure

首先,手动配置网站ccnetiis(有人说安装程序已自动配好,但与本人实际操作不符)。此网站会调用cc.net services。

其次,配置ccnet.config

View Code
<cruisecontrol xmlns:cb="urn:ccnet.config.builder">
  <!-- This is your CruiseControl.NET Server Configuration file. Add your projects below! -->


  <project name="TestCC.Net" description="Learning cc.net daily build.">
        <artifactDirectory>E:\WorkSpace\Projects\TTunit\People\DailyBuild\Artifacts</artifactDirectory>
        <webURL>http://localhost/ccnet</webURL>
    <triggers>
    <!-- check the source control every X time for changes, 
         and run the tasks if changes are found -->
    <intervalTrigger
               name="continuous"
               seconds="1800"
               buildCondition="IfModificationExists"
               initialSeconds="30"/>
    </triggers>

    <sourcecontrol     type="svn" >
        <trunkUrl>project url</trunkUrl>  
    <workingDirectory>E:\WorkSpace\Projects\TTunit\People</workingDirectory>  
    <executable>D:\installPackage\CruiseControl\SVN\Apache-Subversion-1.7.6\bin\svn.exe</executable>  
    <username>your's user name</username>  
    <password>your's password</password>  
    </sourcecontrol> 
    
    <tasks>
        <!--using MsBuild, also could use Nant -->
        <msbuild>
              <executable>C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe</executable>
              <workingDirectory>E:\WorkSpace\Projects\TTunit\People</workingDirectory>
              <projectFile>Fox.Test.CC.sln</projectFile>
              <buildArgs>/p:Configuration=Release</buildArgs>
              <targets>ReBuild</targets>
              <timeout>900</timeout>
              <logger>D:\installed\CruiseControl.NET\server\ThoughtWorks.CruiseControl.MsBuild.dll</logger>
      </msbuild>
      
       <!--unit test-->
          <nunit>
              <path>D:\installed\Nunit2.6\bin\nunit-console.exe</path>
              <assemblies>
                  <assembly>E:\WorkSpace\Projects\TTunit\People\TestTTT\bin\Release\TestTTT.dll</assembly>                  
              </assemblies>
              <excludedCategories>
                  <excludedCategory>LongRunning</excludedCategory>
              </excludedCategories>
              <!--have not works yet -->
              <outputfile>E:\WorkSpace\Projects\TTunit\People\DailyBuild\UnitTest\nunit-results.xml</outputfile>
          </nunit>
          
      <!--<buildpublisher>  
        <sourceDir>E:\Integration\CI2.0\WorkingDir\Release\2.0\_PublishedWebsites</sourceDir>  
        <publishDir>E:\Integration\CI2.0\Release</publishDir>  
      </buildpublisher> -->
          
          <exec executable="E:\WorkSpace\Projects\TTunit\People\DailyBuild\OpenCover.bat" />
          <exec executable="E:\WorkSpace\Projects\TTunit\People\DailyBuild\ReportGenerator.bat" />
          <!--not free, so i can't get latest version <exec executable="E:\WorkSpace\Projects\TTunit\People\DailyBuild\ncover.bat" />-->
          <!--FxCop, haven't use yet-->
          <!--exec executable="D:\\fxcop.bat" -->

          <!--in order to see reports in cc.net website-->
          <merge>
              <files>
                  <!--not sure what effect it takes-->
                  <file>E:\WorkSpace\Projects\TTunit\People\DailyBuild\UnitTest\OpenCover\openCoverTest.xml</file>
                  <!-- Other files to merge for your build would also be included here -->
              </files>
          </merge>
    </tasks>

    <publishers>
          <statistics />
          <xmllogger />
          <email mailport="25" includeDetails="TRUE" mailhostUsername="userName" mailhostPassword="password" useSSL="FALSE">
              <from>sender</from>
              <mailhost>mail host</mailhost>
              <users>
                  <user name="dave" group="developers" address="[email protected]***.com" />
                  <user name="charlie" group="buildMaster" address="[email protected]***.com" />                   
              </users>
              
              <groups>
                  <group name="developers">
                      <notifications>
                          <notificationType>Failed</notificationType>
                          <notificationType>Fixed</notificationType>
                      </notifications>
                  </group>
                  <group name="buildMaster">
                      <notifications>
                          <notificationType>Always</notificationType>
                      </notifications>
                  </group>
              </groups>
              
              <converters>
                  <regexConverter find="$" replace="@foxglobal.com" />
              </converters>
              
              <!--mail subject used on fail sititute-->
              <subjectSettings>
                  <subject buildResult="StillBroken" value="Build is still broken for TestCC.Net" />
              </subjectSettings>              
              
          </email>
      </publishers>
            <externalLinks>
        <externalLink name="OpenConver" url="http://localhost/OpenCover/index.htm" />
    </externalLinks> 
  </project>

</cruisecontrol>

  配置完成后,应该先使用CCValidator.exe验证config文件是否合格。

再次,配置dashboard.config,in order to merge other reports in cc.net website.Corresponding xsl file are in their installed folder

View Code
    <buildPlugins>
      <buildReportBuildPlugin>
        <xslFileNames>
          <xslFile>xsl\header.xsl</xslFile>
          <xslFile>xsl\modifications.xsl</xslFile>
          <xslFile>xsl\tests.xsl</xslFile>
          <xslFile>xsl\timing.xsl</xslFile>
          <xslFile>xsl\OpenCoverSummary.xsl</xslFile>
          <xslFile>xsl\OpenCoverClass.xsl</xslFile>
        </xslFileNames>
      </buildReportBuildPlugin>
      <buildLogBuildPlugin />
      <xslReportBuildPlugin description="NUnit Details" actionName="NUnitDetailsBuildReport" xslFileName="xsl\tests.xsl" />
            <xslReportBuildPlugin description="NUnit Timings" actionName="NUnitTimingsBuildReport" xslFileName="xsl\timing.xsl" />
            <!-- Add the following to replace the legacy NCover xsl with the NCoverExplorer summary -->
            <!--<xslReportBuildPlugin description="OpenCover Report" actionName="OpenCoverBuildReport" xslFileName="xsl\OpenCoverSummary.xsl" />
            <xslReportBuildPlugin description="OpenCover Class Report" actionName="OpenCoverBuildClassReport" xslFileName="xsl\OpenCoverClass.xsl" />-->
    </buildPlugins>

最后,Start cc.net services, and then browser cc.net website, force it.

 

d)Exception in learning progress

1)SVN证书验证失败

 命令行工具checkout repository,选中 (p)ermanently。若在域中,需对ccnet services的登录账号设置为域账号。

 

2)Ncover exception: no data collected

  版本问题。Ncover 3.1不支持.net 4.0。

 

3)SVN operation failed:please see the ‘svn upgrade’ command

  由于workspace是使用tortoise checkout的,版本比VisualSVN低。所以upgrade吧。

 

五、Result

 

View Cover report through external link

email

Summary:

持续集成(二) will include "auto deploy", fxCop... 

 

 

 

 

 

转载于:https://www.cnblogs.com/zzq417/archive/2012/08/31/agile_ccnet1.html