溫暖潔森

          勇敢做自己

            BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
            13 隨筆 :: 1 文章 :: 70 評論 :: 0 Trackbacks
          最近自己出于對項目持續(xù)構(gòu)建感興趣,特花一點時間對這塊進行研究并取得一些不錯的效果,目前使項目達到了自動化構(gòu)建集成的效果,說一下自己的方案

          持續(xù)集成工具:CruiseControl,俗稱cc
          構(gòu)建工具:Ant (Maven不錯,但還未使用熟練)
          應(yīng)用服務(wù)器:tomcat
          版本控制器:Subversion



          1、cc的設(shè)置

          首先下載CruiseControl,目前版本是2.7.1,打開目錄,找到config.xml文件

          <cruisecontrol>
              <project name="sanitation">

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

                  <bootstrappers>
                      <svnbootstrapper localWorkingCopy="projects/${project.name}" />
                             </bootstrappers>

                  <modificationset quietperiod="30">
                      <svn localWorkingCopy="projects/${project.name}"/>
                            </modificationset>

                  <schedule interval="3600">
                     <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>
                      <email mailhost="XXXX" returnaddress="XXX" buildresultsurl="XXXX" skipusers="true" spamwhilebroken="true">
                       <always address=XXX@XXX/>
                         <failure address=XXX@XXX/>
                      </email>
                  </publishers>

              </project>
          </cruisecontrol>


          其中${project.name}根據(jù)實際情況改成自己的項目名稱,<schedule interval="3600">是指過一小時進行下次輪循,這里單位是秒,<publishers>執(zhí)行完畢后可以通過發(fā)送有郵件方式進行通知,上面是成功或失敗都進行通知,這樣 cc環(huán)境就布置完畢

          2、ant腳本

          只摘取關(guān)鍵部分

          <project basedir="." default="deploy-test" name="sanitation">
          <target name="deploy-test" depends="quickstart,fun-test,test" />

          <!-- ===================================
             把打包的文件拷貝到tomcat目錄下
            ==================================== -->
           <target name="quickstart" depends="war" description="santation程序">
            <echo message="打包部署開始..." />
            <antcall target="tomcat.stop" />
            <delete dir="${server.deploy}/${ant.project.name}" />
            <delete file="${server.deploy}/${ant.project.name}.war" />
            <copy todir="${server.deploy}" file="${release.warfile}" />
            <echo message="打包部署結(jié)束..." />
           </target>

          <!-- 執(zhí)行Selenium Web功能測試 -->
           <target name="fun-test" depends="compile">
            <path id="selenium.server.runtime">
             <fileset dir="lib/test" includes="selenium-server-*.jar" />
            </path>

            <delete dir="${functional_test.data}/**" />
            

            <antcall target="tomcat.start" />
            <antcall target="selenium.server.start" />

            <junit printsummary="yes" fork="true" errorProperty="test.failed" failureProperty="test.failed">
             <classpath>
              <path refid="test.classpath" />
              <path location="${test.build}" />
             </classpath>
             <formatter type="xml" />
             <formatter type="brief" usefile="false" />

             <test name="${testcase}" if="testcase" />
             <batchtest todir="${functional_test.data}" unless="testcase">
              <fileset dir="${test.build}">
               <include name="**/view/*Test.class" />
              </fileset>
             </batchtest>
            </junit>
            <antcall target="tomcat.stop" />
            <if>
             <istrue value="${test.failed}" />
             <then>
              <functional_test-report report.dir="${functional_test.report}" data.dir="${functional_test.data}" />
              <fail>Unit tests 失敗. 請于${functional_test.report}目錄觀看錯誤信息報表.</fail>
             </then>
            </if>
           </target>

          <!-- 執(zhí)行JUNIT功能測試 -->

          <target name="test" depends="compile">

            <!-- 檢查 junit.jar -->
            <available classname="junit.framework.TestCase" property="junit.present" />
            <fail unless="junit.present" message="Please copy lib/junit-3.8.1.jar into env.ANT_HOME/lib or Class Path" />
            <!-- 清除上次的data數(shù)據(jù) -->
            <delete dir="${test.data}" />
            <mkdir dir="${test.data}" />
            <!-- 執(zhí)行測試 -->
            <junit printsummary="yes" fork="true" errorProperty="test.failed" failureProperty="test.failed">
             <classpath>
              <path refid="test.classpath" />
              <path location="${test.build}" />
             </classpath>
             <formatter type="xml" />
             <formatter type="brief" usefile="false" />

             <!-- 執(zhí)行單個或批量的test case。
              如果在命令行有定義testcase,
              如: ant -Dtestcase=com.gresoft.sanitation.test.MyTestCase
              則執(zhí)行單個test case. -->
             <test name="${testcase}" if="testcase" />

             <batchtest todir="${test.data}">
              <fileset dir="${test.build}">
               <exclude name="**/functional/**/*Test.class" />
               <exclude name="**/view/*Test.class" />
               <include name="**/*Test.class" />
              </fileset>
             </batchtest>
            </junit>
            <if>
             <istrue value="${test.failed}" />
             <then>
              <test-report report.dir="${test.report}" data.dir="${test.data}" />
              <fail>Unit tests 失敗. 請于${test.report}目錄觀看錯誤信息報表.</fail>
             </then>
            </if>
           </target>


          此腳本主要目的是自動從svn服務(wù)器上更新最新程序并進行編譯,部署,selenium頁面測試,junit功能測試的過程,并自動把運行后結(jié)果以郵件形式進行提醒,這樣整個流程就算結(jié)束,然后一小時后cc自動進行下一次的自動構(gòu)建過程


          問題:其中腳本中  <antcall target="tomcat.stop" />是過程中必須要加入的,如果腳本執(zhí)行完tomcat還沒關(guān)閉,cc會一直處于停止?fàn)顟B(tài),一小時后也不會繼續(xù)輪循,因為它需要等待一個返回信息目前這好象是cc一個bug

          詳情看:http://confluence.public.thoughtworks.org/display/CC/Starting+a+server+with+cc

          好處:使用此方式可以每小時能跟蹤項目中各組員項目開發(fā)情況,并對系統(tǒng)功能進行持續(xù)測試,把問題可以及時進行反饋以便解決,其中項目中測試完整性是整個過程的最關(guān)鍵部分,測試完整加上持續(xù)集成工具就可以達到項目自動構(gòu)建集成功能


          這是自己一些簡要的步驟,如大家有興趣我可以以后提供更為詳細的步驟!


          一些截圖

           




          參考資料     CruiseControl step by step 搭建你的持續(xù)集成服務(wù)器

          posted on 2008-01-03 11:51 harry520 閱讀(2160) 評論(3)  編輯  收藏 所屬分類: J2EE

          評論

          # re: 關(guān)于每日構(gòu)建|每小時構(gòu)建[未登錄] 2008-01-05 14:32 切爾斯基
          在瀏覽器中輸入 http://10.62.1.11:9001/dashboard/, 你會看到全新的CruiseControl的界面  回復(fù)  更多評論
            

          # re: 關(guān)于每日構(gòu)建|每小時構(gòu)建 2008-01-06 16:13 wuxj888java
          有一篇參考文章
          http://www.aygfsteel.com/chelsea/archive/2008/01/05/173004.html  回復(fù)  更多評論
            

          # re: 關(guān)于每日構(gòu)建|每小時構(gòu)建 2009-04-08 10:19 zyf
          寫的是蠻詳細的,但是能否再加上注釋啊?有些步驟看的不太明白呢  回復(fù)  更多評論
            

          主站蜘蛛池模板: 聂荣县| 醴陵市| 北碚区| 通化县| 侯马市| 新密市| 军事| 永年县| 大宁县| 闽侯县| 平阴县| 九江市| 拜泉县| 砀山县| 洮南市| 航空| 龙里县| 文昌市| 吉隆县| 平邑县| 苏尼特右旗| 平顶山市| 高邮市| 白水县| 蒙城县| 那曲县| 稷山县| 泸州市| 穆棱市| 拉萨市| 内乡县| 道孚县| 宿松县| 屯昌县| 昭通市| 东方市| 聂荣县| 兰州市| 康马县| 浦县| 京山县|