使用Cruisecontrol实现Flex项目的持续集成

使用Cruisecontrol实现Flex项目的持续集成

 

持续集成是敏捷开发中的最佳实践之一,它强调要频繁的集成,每次源代码更改之后要通过所有的测试,如果一次构建不成功,开发者可以很快得到反馈,及时修改,降低项目的风险。关于详细的介绍,可以参考Martin FowlerContinuous Integration.

 

我们的项目使用的持续集成工具是目前流行的Cruisecontrol ,使用的版本控制系统是Perforce,现在网上关于svn, cvs等工具的资料较多,关于Perforce的比较少,我把自己在搭建Flex项目的持续集成环境中遇到的问题以及解决方法整理一下,希望对缺少这方面资料的人有些帮助。

 

1:下载Cruisecontrolhttp://cruisecontrol.sourceforge.net目前最新的版本是2.7.3,建议下载src版本,因为在生成报告构建结果的应用程序时需要手动来build

 

2:写Cruisecontrol的配置文件config.xml,之前需要建立合适的目录结构,可以参考网上的资料。

 

<!--根节点-->

 

<cruisecontrol>

 

<!--定义项目的信息,一个<cruisecontrol>下可以有多个<project>节点-->

 

 <project name="AIRClient" buildafterfailed="true">

 

<!--定义一些可以在下面使用的属性键值对,由于cruisecontrol 间隔一定时间就检查Perforce上的代码是否有更改,因此需要指定Perforce服务器以及客户端的信息:

P4_PORT的值为Perforce服务器的名字:端口;

P4_CLIENT的值为本机p4 client的名字,如果查询不到,可以在Perforce的官网上下载p4 command-line client的一个工具,运行p4 client命令,会打开一个txt文件,里面会显示客户端的所有信息,其中有一项是”ROOT”,它指向的值是从Perforce上取到的源代码自动存放的地方,可以根据自己的需要修改它,将下载的源代码存放在自己指定的合适的地方。一个用户可以有多个client,可以用该工具创建多个client.

P4_USER是本机p4 client的用户名

P4_PASSWD是本机p4 client的密码-->

 

       <property name="P4_PORT" value="peuck:1710" />

       <property name="P4_CLIENT" value="Jissie-xp" />

       <property name="P4_USER" value="guang" />

       <property name="P4_PASSWD" value="pass1234" />

                                   

<listeners>

<!--cruisecontrol会把构建的状态信息记录在下面的文件中-->

      <currentbuildstatuslistener

          file="logs/AIRClient/status.txt"/>

    </listeners>

 

    <!-- Bootstrappers are run every time the build runs,

        *before* the modification checks -->

    <bootstrappers>

    </bootstrappers>

 

    <!-- Defines where cruise looks for changes, to decide

         whether to run the build -->

<!-- quietperiod指定在最后一次代码check in之后的10秒后构建。防止代码没有完全check in就可以构建。View指定的是项目在Perforce服务器上的路径,使用能够把目录下的所有文件取出-->

    <modificationset quietperiod="10">

      <p4 port="${P4_PORT}"

                                      client="${P4_CLIENT}"

                                      user="${P4_USER}"

                                      passwd="${P4_PASSWD}"

                                      view="//HL/AIRClient/..."/>

    </modificationset>

 

    <!-- Configures the actual build loop, how often and which

         build file/target -->

<!— interval指定cruisecontrol每隔多少时间检查Perforce代码是否有更新,本例中为60秒;ant命令调用antbuild文件,如果代码有更新,则开始运行antbuild文件,anthome指定ant.bat所在的路径,buildfile指定ant.bat要运行的build文件的名称,target指定运行的是哪个ant targetmultiple=1指定每次都要运行这个target.-->

 

    <schedule interval="60">

        <ant anthome="C:/cc-sandbox/cruisecontrol-bin-2.7.3/apache-ant-1.7.0"

           buildfile="p4-build-wrapper.xml"

           target="experimentBuild"

           uselogger="true"

           usedebug="false"

           multiple="1"/>

 

<!—multiple=5指定每构建5次运行一次target="cleanbuild"-->                     

        <ant anthome="C:/cc-sandbox/cruisecontrol-bin-2.7.3/apache-ant-1.7.0"

           buildfile="p4-build-wrapper.xml"

           target="cleanbuild"

           uselogger="true"

           usedebug="false"

           multiple="5"/>

    </schedule>

 

    <!-- directory to write build logs to -->

    <log logdir="logs/AIRClient"/>

 

<!-- Publishers are run *after* a build completes -->

<!—publishers指定如何把构建的结果表示出来,本例选择将显示构建结果的网页写在一个邮件中发送到指定的邮箱:mailhost是要发送邮件的SMTP服务器的名字,username是该服务器能识别的用户,一般用自己的收邮件客户端的帐号,returnaddress 是该邮件显示的发送人的邮箱,buildresultsurl 是显示构建结果的网页的路径-->

 

    <publishers>

         <email mailhost="apacmail. com"

                                                username="guang"

                                                password="gl_0304"

                                                returnaddress="guang@yye.com"

                                                defaultsuffix=""

                                                buildresultsurl="http://10.132.119.163:8080">

 

<!—always指定的邮箱地址是每次构建结果都会发送,不论构建成功或者失败,failure指定的是构建失败发送的邮箱地址-->

 

            <always address="guang@yye.com" />

                                                <always address="wyhe@ayybe.com"/>

                                                <always address="yluo@adoy.com"/>

            <failure address="gyng@abe.com" />

         </email>

    </publishers>

  </project>

 

</cruisecontrol>

 

3:写build文件:

<?xml version="1.0"?>

<project name="airclient" default="experimentBuild" basedir=".">

            <property environment="env" />

            <property name="P4_PORT" value="peuck:1710" />

            <property name="P4_CLIENT" value="Jissie-xp" />

            <property name="P4_USER" value="guang" />

            <property name="P4_PASSWD" value="pass1234" />

            <property name="p4.view" value="//HL/AIRClient/..."/>

            <property name="experiment.dir" value="${basedir}/checkout/Experiment"/>

           

            <!--if AIRClient has changed, get latest source code from perforce-->

    <target name="checkout">       

        <p4sync port="${P4_PORT}"

                          user="${P4_USER}"

                          view="${p4.view}"

                          client="${P4_CLIENT}"

                          force="true" />

    </target>     

           

            <!--call AIRClient build file to build souce code and generate headlights.swc-->

            <target name="masterbuild" depends="checkout,copyAirBuildFile">

                        <ant inheritall="false"

                                    antfile="build.xml"

                                    dir="${basedir}/checkout/AIRClient/Source"

                                    target="compile"/>

            </target>

           

            <!--call AIRClient build file to clean project-->

            <target name="cleanbuild" depends="checkout">

                        <ant inheritall="false"

                                    antfile="build.xml"

                                    dir="${basedir}/checkout/AIRClient/Source/build"

                                    target="clean"/>

            </target>

           

            <target name="experimentBuild" depends="masterbuild,copySWCFile">

                        <ant inheritall="false"

                                    antfile="build.xml"

                                    dir="${experiment.dir}"

                                    target="main"/>

            </target>

           

            <!-- because ant dir in config.xml is the basedir of AIRClient build file, so I need to copy the build.xml file to its base dir-->

            <target name="copyAirBuildFile">

       <copy todir="${basedir}/checkout/AIRClient/Source">

                                    <fileset dir="${basedir}/checkout/AIRClient/Source/build">

                                                <include name="build.properties"/>

                                                <include name="build.xml"/>

                                    </fileset>

                        </copy>

   </target>

  

   <!--when AIRClient source code changes, first build and generate headlights.swc file, then copy this file to project Experiment as a lib file-->

   <target name="copySWCFile">

       <copy file="${basedir}/checkout/AIRClient/Source/bin/headlights.swc"

                                    tofile="${experiment.dir}/libs/headlights.swc"/>

   </target>

  

</project>

4:配置显示构建结构的网页,下载tomcat服务器。。。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值