持續集成(Continuous Integration)


持續集成簡稱CI,持續集成是頻繁、持續的在多個團隊成員的工作中進行集成,並且給與反饋。一個典型的持續集成周期包括以下幾個步驟:
   1. 持續集成服務器不斷從版本控制服務器上檢查代碼狀態,看代碼是否有更新。
   2. 如果發現代碼有最新的提交,那么就從版本控制服務器下載最新的代碼。
   3. 等代碼完全更新以后,調用自動化編譯腳本,進行代碼編譯。
   4. 運行所有的自動化測試。
   5. 進行代碼分析。
   6. 產生可執行的軟件,能夠提供給測試人員進行測試。
   持續集成服務器,比如CruiseControl或者VSTS
   CruiseControl, Anthill, Bamboo, TeamCity, Continuum,hudson

一個開源的持續繼承環境:Jenkins

下面就來介紹一下這個軟件的安裝,ubuntu 11.10環境為例

一、安裝Jenkins

去官網下載,安裝,很簡單,他自己集成了一個java的環境和服務器,一個包搞定問題

安裝集成工具

1、安裝: ANT

sudo apt-get install ant

2、安裝:pear

sudo apt-get install php-pear

3、安裝:xdebug

4、安裝:phpunit

sudo pear channel-discover pear.phpunit.de

sudo pear install phpunit/PHPUnit

5、安裝:PHP_CodeSniffer

sudo pear install PHP_CodeSniffer

四、創建任務

  1. 下載模版配置:
    cd $JENKINS_HOME/jobsgit clone git://github.com/sebastianbergmann/php-jenkins-template.git php-templatechown -R jenkins:nogroup php-template/
  2. 重啟Jenkins CLI:
    java -jar jenkins-cli.jar -s http://localhost:8080 reload-configuration
  3. 新建任務.
  4. 輸入任務名稱.
  5. 選擇從已有任務拷貝
  6. 取消”Disable Build” 選項.
  7. 填寫相關信息.
  8. 填寫相關svn信息.
  9. 保存

下面是項目build.xml文件(目前我們使用的配置)

==========build.xml============

<?xml version=”2.0″ encoding=”UTF-8″?>
<project name=”name-of-project” default=”build”>
<target name=”build”
depends=”prepare,lint,phploc,phpcs-ci,phpunit,phpcb”/>

<target name=”build-parallel”
depends=”prepare,lint,tools-parallel,phpunit,phpcb”/>

<target name=”tools-parallel”
description=”Run tools in parallel”>
<parallel threadCount=”2″>
<antcall target=”phpcs-ci”/>
<antcall target=”phploc”/>
</parallel>
</target>

<target name=”clean” description=”Cleanup build artifacts”>
<delete dir=”${basedir}/build/api”/>
<delete dir=”${basedir}/build/code-browser”/>
<delete dir=”${basedir}/build/coverage”/>
<delete dir=”${basedir}/build/logs”/>
</target>

<target name=”prepare” depends=”clean”
description=”Prepare for build”>
<mkdir dir=”${basedir}/build/api”/>
<mkdir dir=”${basedir}/build/code-browser”/>
<mkdir dir=”${basedir}/build/coverage”/>
<mkdir dir=”${basedir}/build/logs”/>
</target>

<target name=”lint”>
<apply executable=”php” failonerror=”true”>
<arg value=”-l” />

<fileset dir=”${basedir}”>
<include name=”**/*.php” />
<modified />
</fileset>

<fileset dir=”${basedir}/_test”>
<include name=”**/*.php” />
<modified />
</fileset>
</apply>
</target>

<target name=”phploc” description=”Measure project size using PHPLOC”>
<exec executable=”phploc”>
<arg value=”–log-csv” />
<arg value=”${basedir}/build/logs/phploc.csv” />
<arg path=”${basedir}” />
</exec>
</target>

<target name=”phpcs-ci”
description=”Find coding standard violations using PHP_CodeSniffer creating a log file for the continuous integration server”>
<exec executable=”phpcs” output=”/dev/null”>
<arg value=”–report=checkstyle” />
<arg value=”–report-file=${basedir}/build/logs/checkstyle.xml” />
<arg value=”–standard=MyStandard” />
<arg value=”–ignore=${basedir}/wind,${basedir}/_test,${basedir}/configs,${basedir}/www,${basedir}/data,${basedir}/library/utility/safehtml,${basedir}/library/utility/soap” />
<arg path=”${basedir}” />
</exec>
</target>

============end===============

 

phpunit的配置

============phpunit.xml=============

<?xml version=”1.0″ encoding=”UTF-8″?>
<phpunit bootstrap=”_test/bootstrap.php” backupGlobals=”false” backupStaticAttributes=”false” strict=”true” verbose=”true”>
<testsuites>
<testsuite name=”BankAccount”>
<directory suffix=”Test.php”>_test/market</directory>
</testsuite>
</testsuites>
<logging>
<log type=”coverage-clover” target=”build/logs/clover.xml” />
<log type=”coverage-html” target=”build/coverage” title=”BankAccount” />
<log type=”junit” target=”build/logs/junit.xml” logIncompleteSkipped=”false” />
</logging>
</phpunit>

============end=================

進入jenkins的任務目錄,一般是在:/var/lib/jenkins/jobs/

進入指定的job/workspace目錄

替換目錄中的的build.xml和phpunit.xml文件

重啟jenkins

參考:http://avnpc.com/pages/php-open-source-project-plus-travis-ci

http://blog.windcache.com/archives/5

http://blog.csdn.net/wanghantong/article/details/40985653


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM