寒哥管理的技术专题PHP实战程序员

PHP+Jenkins 持续集成

2017-04-06  本文已影响1008人  靖小侠

持续集成解决的问题

主要使用工具

环境搭建

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
service jenkins start
Role Strategy(基于角色的权限管理)
Publish Over SSH Plugin(通过ssh发布代码)
Phing(php构建工具)
PMD(代码静态检查)
Plot
JDepend
DRY
公私钥 配置 SSH Servers -1 配置 SSH Servers -2

最后点击测试 看一下是否成功。

<?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" />
        <!--####程序的目录(根据实际情况更改)-->
        <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>
        <!--####集成构建相关配置-->
        <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代码规模分析工具配置-->
        <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代码静态检查工具配置-->
        <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>
        <!--####构建参数配置-->
        <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>
        <!--####构建参数配置-->
        <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>

创建项目

Build after other projects are built:在其他项目触发的时候触发,里面有分为三种情况,也就是其他项目构建成功、失败、或者不稳定(这个不稳定我这里还木有理解)时候触发项目
Poll SCM:定时检查源码变更(根据SCM软件的版本号),如果有更新就checkout最新code下来,然后执行构建动作。我的配置如下:
*/5 * * * * (每5分钟检查一次源码变化)
Build periodically:周期进行项目构建(它不care源码是否发生变化),我的配置如下:
0 2 * * * (每天2:00 必须build一次源码)

构建完成后的操作-1 构建完成后的操作-2 构建完成后的操作-3

最后保存回到主页点击构建 测试部署。

上一篇 下一篇

猜你喜欢

热点阅读