持續(xù)集成解決的問題
- 統(tǒng)一代碼發(fā)布
- 自動構(gòu)建工程
- 多機(jī)自動化部署
主要使用工具
- LINUX服務(wù)器
- 集成工具Jenkins
- 構(gòu)建工具Phing
環(huán)境搭建
- jenkins+php安裝
wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo
rpm --import https://jenkins-ci.org/redhat/jenkins-ci.org.key
yum install jenkins
yum install java
yum install java-1.6.0-openjdk
yum install php
yum install php-devel
yum install php-pear
yum install re2c
yum install php-pecl-imagick
yum install php-dom
yum install php-pear-phing
yum install php-phpunit-PHPUnit
yum install php-phpunit-phpcpd
pear channel-discover pear.phpmd.org
pear remote-list -c pdepend
pear install --alldeps pdepend/PHP_Depend
pear install --alldeps phpmd/PHP_PMD
- 啟動jenkins瀏覽器訪問 (服務(wù)器IP:8080)
service jenkins start
-
安裝拓展
注:首次進(jìn)入可以選擇默認(rèn)安裝拓展
在瀏覽器打開 系統(tǒng)管理->管理插件->可選插件 搜索以下必須安裝的拓展:
Role Strategy(基于角色的權(quán)限管理)
Publish Over SSH Plugin(通過ssh發(fā)布代碼)
Phing(php構(gòu)建工具)
PMD(代碼靜態(tài)檢查)
Plot
JDepend
DRY
- 配置ssh面密碼登錄
注:發(fā)布機(jī)->jenkins所在的服務(wù)器 生產(chǎn)機(jī)->運(yùn)行項(xiàng)目的服務(wù)器
在發(fā)布機(jī)生成公私鑰
ssh-keygen -t rsa
在/root/.ssh/可以看到兩個(gè)文件
公私鑰
- 將公鑰發(fā)送到發(fā)布機(jī)
將發(fā)布機(jī)上的 /root/.ssh/id_rsa.pub 傳送到 生產(chǎn)機(jī)的 .ssh/(目錄沒有.ssh請創(chuàng)建)
將 id_rsa.pub 改名為 authorized_keys
測試無密碼鏈接 ssh 生產(chǎn)機(jī)IP - 在Jenkins配置ssh源
系統(tǒng)管理->系統(tǒng)設(shè)置
在頁面找到Publish over SSH欄
配置 SSH Servers 如圖:
配置 SSH Servers -1
配置 SSH Servers -2
最后點(diǎn)擊測試 看一下是否成功飞蚓。
- 在svn的項(xiàng)目的根目錄下創(chuàng)建build.xml
<?xml version="1.0" encoding="UTF-8"?>
<project name="test-corn" default="build">
<target name="build" depends="make_runtime,pdepend,phpmd,phpcpd,test,check,test-cron"/>
<property name="version-m" value="1.1" />
<property name="version" value="1.1.0" />
<property name="stability" value="stable" />
<property name="releasenotes" value="" />
<property name="tarfile" value="${phing.project.name}.${buildnumber}.${buildid}.tar.gz" />
<property name="pkgfile" value="${phing.project.name}.${version}.tgz" />
<property name="distfile" value="dist/${tarfile}" />
<property name="tests.dir" value="tests" />
<!--####程序的目錄(根據(jù)實(shí)際情況更改)-->
<fileset id="test-cron.tar.gz" dir="./trunk">
<include name="Application/**"/>
<exclude name="Application/Common/Conf/config.php"/>
<exclude name="Application/Runtime/**"/>
<include name="Public/**"/>
<include name="ThinkPHP/**"/>
<include name="*.php"/>
</fileset>
<!--####集成構(gòu)建相關(guān)配置-->
<target name="make_runtime">
<mkdir dir="${project.basedir}/Runtime" />
<mkdir dir="${project.basedir}/build/logs" />
<mkdir dir="${project.basedir}/build/pdepend" />
<mkdir dir="${project.basedir}/build/code-browser" />
</target>
<!--####php代碼規(guī)模分析工具配置-->
<target name="pdepend" description="Calculate software metrics using PHP_Depend">
<exec executable="pdepend">
<arg value="--jdepend-xml=${project.basedir}/build/logs/jdepend.xml"/>
<arg value="--jdepend-chart=${project.basedir}/build/pdepend/dependencies.svg"/>
<arg value="--overview-pyramid=${project.basedir}/build/pdepend/overview-pyramid.svg"/>
<arg path="${project.basedir}/"/>
</exec>
</target>
<!--####php代碼靜態(tài)檢查工具配置-->
<target name="phpmd" description="Perform project mess detection using PHPMD">
<phpmd>
<fileset dir="${project.basedir}">
<include name="protected/*.php" />
<include name="*.php" />
</fileset>
</phpmd>
</target>
<!--####php代碼分析工具配置-->
<target name="phpcpd" description="Find duplicate code using PHPCPD">
<phpcpd>
<fileset dir="${project.basedir}">
<include name="*.php" />
</fileset>
<formatter type="pmd" outfile="pmd-cpd.xml"/>
</phpcpd>
</target>
<!--####php單例測試配置-->
<target name="test" description="Run PHPUnit tests">
<phpunit haltonerror="true" haltonfailure="true" printsummary="true">
<batchtest>
<fileset dir="${tests.dir}">
<include name="**/*Test.php" />
</fileset>
</batchtest>
</phpunit>
</target>
<!--####構(gòu)建參數(shù)配置-->
<target name="check" description="Check variables" >
<fail unless="version" message="Version not defined!" />
<fail unless="buildnumber" message="buildnumber not defined!" />
<fail unless="buildid" message="buildid not defined!" />
<delete dir="dist" failonerror="false" />
<mkdir dir="dist" />
</target>
<!--####構(gòu)建參數(shù)配置-->
<target name="test-cron" depends="check" description="Create tar file for release">
<echo msg="Creating distribution tar for ${phing.project.name} ${version}"/>
<delete file="${distfile}" failonerror="false"/>
<tar destfile="${distfile}" compression="gzip">
<fileset refid="test-cron.tar.gz"/>
</tar>
</target>
</project>
創(chuàng)建項(xiàng)目
-
在首頁->新建->構(gòu)建一個(gè)自由風(fēng)格的軟件項(xiàng)目
創(chuàng)建項(xiàng)目 -
配置SVN
配置SVN -
配置構(gòu)建觸發(fā)的條件 默認(rèn)是手動構(gòu)建
觸發(fā)條件
Build after other projects are built:在其他項(xiàng)目觸發(fā)的時(shí)候觸發(fā),里面有分為三種情況吨拍,也就是其他項(xiàng)目構(gòu)建成功枣宫、失敗婆誓、或者不穩(wěn)定(這個(gè)不穩(wěn)定我這里還木有理解)時(shí)候觸發(fā)項(xiàng)目
Poll SCM:定時(shí)檢查源碼變更(根據(jù)SCM軟件的版本號),如果有更新就checkout最新code下來也颤,然后執(zhí)行構(gòu)建動作洋幻。我的配置如下:
*/5 * * * * (每5分鐘檢查一次源碼變化)
Build periodically:周期進(jìn)行項(xiàng)目構(gòu)建(它不care源碼是否發(fā)生變化),我的配置如下:
0 2 * * * (每天2:00 必須build一次源碼)
-
php使用Phing拖拽構(gòu)建
php使用Phing拖拽構(gòu)建-1
php使用Phing拖拽構(gòu)建-2 - 設(shè)置構(gòu)建完成后的操作(文檔保存和ssh部署)
構(gòu)建完成后的操作-1
構(gòu)建完成后的操作-2
構(gòu)建完成后的操作-3
最后保存回到主頁點(diǎn)擊構(gòu)建 測試部署翅娶。