posts - 7,comments - 1,trackbacks - 0

持续集成的概念
      持续集成是“极限编程”提出的理论,持续集成的关键是代码构建的完全自动化,读取源代码、编译、连接、测试,整个创建过程都应该自动完成。对于一次成功的创建,要求在这个自动化过程中的每一个步都不能出错,而最重要的一步是测试,只有最后通过测试的创建才是成功的创建。
      cc(cruisecontrol)我不是第一次接触,在我负责第一个项目中就启用此工具,当时版本比较低,研究了几天就简单配好了,难点在于一般文档都是介绍cvs的,而我们公司用的是SVN,因此研究svn的配置花费了1点时间。我非常感谢掌晨雪编写的《持续集成实践之CruiseControl》文档,对我起了很大的帮助!

      cruisecontrol2.7是最新的版本,这个版本和以前相比,更加方便,并且增加了一个新的功能Dashboard,详情可以参看CruiseControl官方网站http://cruisecontrol.sourceforge.net/。这个版本还提供一个简单的例子,下载cruisecontrol-bin-2.7.2.zip并解压。在里面会找到projects、logs目录,在以前是没有的,这些都是要自己手动创建的,现在这个版本方便多了。在这两个目录下可以发现connectfour范例目录。
      来一下cruisecontrol的实现机制吧,如下图所示:
Architecture Diagram

Build Loop:
      持续集成最重要的特征之一就是自动话,而CC的Build Loop就是为支持自动化而设计的,Build Loop也是CC的核心。

      Build Loop从字面上理解就是循环创建的意思,CC提供了一个daemon进程,该进程根据配置的时间间隔(也可以指定某个具体时间)读取CC配置文件并进行循环创建(build cycle),每次CC都会重新加载配置文件config.xml(修改了配置文件不用重新启动CC)。

      Build Loop过程中所做的工作如下:访问源码控制系统,查看是否有代码被修改,如果有,获取源码的新版本,并根据配置对源代码进行一次Build,创建一个日志文件,最后项开发人员通知build的结果,活动图如下:

因为Build Loop是根据配置文件的内容来进行的,根据上面Build Loop所做的工作,我们大概可以猜出配置信息主要应该包括:定时创建的时间和源码库访问信息,创建任务信息(如指定Ant文件),记录日志(创建结果),通知(通知内容可以订制)。

CC配置文件:
CC配置文件范connectfour范例如下:

Config.xml<cruisecontrol>
    <project name="connectfour">

        <listeners>
            <currentbuildstatuslistener file="logs/${project.name}/status.txt"/>
        </listeners>

        <bootstrappers>
            <antbootstrapper anthome="apache-ant-1.7.0" buildfile="projects/${project.name}/build.xml" target="clean" />
        </bootstrappers>

        <modificationset quietperiod="30">
            <!-- touch any file in connectfour project to trigger a build -->
            <filesystem folder="projects/${project.name}"/>
        </modificationset>

        <schedule interval="300">
            <ant anthome="apache-ant-1.7.0" buildfile="projects/${project.name}/build.xml"/>
        </schedule>

        <log>
            <merge dir="projects/${project.name}/target/test-results"/>
        </log>

        <publishers>
            <onsuccess>
                <artifactspublisher dest="artifacts/${project.name}" file="projects/${project.name}/target/${project.name}.jar"/>
            </onsuccess>
        </publishers>

    </project>
</cruisecontrol>

 

<cruisecontrol>根元素是<cruisecontrol>,该元素很简单,没什么需要配置的属性。

 
<project>目前CC支持多项目(multiproject),因此可以有多个并行的<project>元素。支持的子元素包括:
 <project>
      <property/>
      <plugin/>
      <dateformat/>
      <labelincrementer/>
      <listeners>
         <cmsynergysessionmonitor/>
         <currentbuildstatusftplistener/>
         <currentbuildstatuslistener/>
         <currentbuildstatuspagelistener/>
         <lockfilelistener/>
      </listeners>
      <bootstrappers>
         <accurevbootstrapper/>
         <alienbrainbootstrapper/>
         <antbootstrapper/>
         <clearcasebootstrapper/>
         <clearcaseviewstrapper/>
         <cmsynergybootstrapper/>
         <currentbuildstatusbootstrapper/>
         <currentbuildstatusftpbootstrapper/>
         <cvsbootstrapper/>
         <execbootstrapper/>
         <gitbootstrapper/>
         <harvestbootstrapper/>
         <lockfilebootstrapper/>
         <mercurialbootstrapper/>
         <p4bootstrapper/>
         <plasticscmbootstrapper/>
         <snapshotcmbootstrapper/>
         <starteambootstrapper/>
         <surroundbootstrapper/>
         <svnbootstrapper/>
         <tfsbootstrapper/>
         <vssbootstrapper/>
      </bootstrappers>
      <modificationset>
         <accurev>
         <alienbrain/>
         <alwaysbuild/>
         <buildstatus/>
         <clearcase/>
         <cmsynergy/>
         <compound>
            <targets/>
            <triggers/>
         </compound>
         <cvs/>
         <darcs/>
         <filesystem/>
         <forceonly/>
         <git/>
         <harvest/>
         <httpfile/>
         <mavensnapshotdependency/>
         <maven2snapshotdependency/>
         <mercurial/>
         <mks/>
         <p4/>
         <plasticscm/>
         <pvcs/>
         <snapshotcm/>
         <starteam/>
         <store/>
         <surround/>
         <svn/>
         <tfs/>
         <timebuild>
         <ucm>
         <veto/>
         <vss/>
         <vssjournal/>
      </modificationset>
      <schedule>
         <ant/>
         <maven/>
         <maven2/>
         <pause/>
         <nant/>
         <phing/>
         <rake/>
         <exec/>
         <composite/>
      </schedule>
      <log>
         <merge/>
<gzip/>
<delete/>
      </log>
      <publishers>
         <antpublisher/>
         <artifactspublisher/>
         <clearcasebaselinepublisher/>
         <cmsynergybaselinepublisher/>
         <cmsynergytaskpublisher/>
         <compoundpublisher/>
         <currentbuildstatuspublisher/>
         <currentbuildstatusftppublisher/>
         <email/>
         <execute/>
         <ftppublisher/>
         <htmlemail/>
         <http>
         <jabber/>
         <onfailure/>
         <onsuccess/>
         <rss/>
         <sametimeannouncement/>
         <scp/>
         <sfeedocman/>
         <sfeefrs/>
         <sfeetracker/>
         <socket/>
         <weblog>
         <x10/>
         <xsltlogpublisher/>
         <yahoopublisher/>
      </publishers>
   </project>

 子元素详情可以参看官方文档的说明。
这里只介绍几个常用的子元素:

<bootstrappers><bootstrappers>在创建之前会运行,相当于一个预处理的作用,<bootstrappers>下面每个子元素都是独立的,因此可以同时配置多个bootstrappers。
CC提供的bootstrappers包括两种,一种用于向其他插件提供项目当前创建的状态,还有一种是从某个源码控制系统更新本地文件,其中最常用的就是<currentbuildstatusbootstrapper>和<svnbootstrappers>。
<currentbuildstatusbootstrapper>指定了状态文件的位置,主要是用来访问项目当前创建的状态,CC的<currentbuildstatusbootstrapper>会将创基爱你的状态写入这个文件。
<svnbootstrapper>的作用有点难理解,因为我们每次项目的创建都应该基于最新的代码,因此在创建之前就要获得最新的项目文件,如果使用的是ant来完成这个任务,那么buildfile本身在创建开始之前发生了变化,我们是不是应该先更新这个buildfile,然后才通过buildfile来对项目进行构建呢?<svnbootstrapper>就是为从源码控制系统更新buildfile文件而设计的(还有一种替代的使用方法是使用wrapper buildfile,这样就不用使用<svnbootstrapper>了,wrapper buildfile也是推荐的方法,<modificationset>部分会进行详细的讨论)。

<modificationset><modificationset>包括了SourceControl插件的配置信息,用于检查各个源码控制系统中是否发生变化,<schedule>会用到这里的配置信息,如果检测到变化,会触发创建过程。
<modificationset>的属性quietperiod(单位为秒)定义了一个时间值。如果CC检查到了变化,会自检查到变化的源码控制系统的最后一次check in 的时间开始等待,等待时间由quietperiod决定,等待结束之后才触发创建(build)过程,主要是防止有人在check in的过程当中就触发创建过程(可能check in只做了一半,这个时候触发创建显然是不正确的)。
下面是一个modificationset的例子:
例子:<modificationset quietperiod="30">
            <svn localworkingcopy="projects/SFA"/>
</modificationset>

未完成,待续...
posted on 2008-04-24 10:40 小胡子 阅读(648) 评论(0)  编辑 收藏 引用 所属分类: 技术知识
只有注册用户登录后才能发表评论。