http://d.hatena.ne.jp/Yamashiro0217/20110619/1308491991
PHPの設定
必要なライブラリ、ツールのインストール
yum install php-xml pear channel-discover pear.phing.info pear channel-discover pear.pdepend.org pear channel-discover pear.phpmd.org pear channel-discover pear.phpunit.de pear channel-discover components.ez.no pear channel-discover pear.symfony-project.com pear install phing/phing pear install pdepend/PHP_Depend pear install phpmd/PHP_PMD pear install phpunit/phpcpd pear install PHPDocumentor pear install --alldeps phpunit/PHPUnit
もしインストール中に他に必要なライブラリがある場合は、状況に応じてインストールする。
各ツールの説明
- phing
- PHP版ant
- PHPMD
- 使われていない変数があるか等のソースチェックをする
- PHPCPD
- 重複コードがあるか等のソースチェックをする
- PHPDocumentor
- PHPDocを生成する
- PHPUnit
- テスト・ツール
Jenkins の設定
jenkins のインストール等はJenkinsを参照
プラグインのインストール
ブラウザでもインストールできるが、 CUIでインストール
wget -O jenkins-cli.jar http://localhost:8080/jnlpJars/jenkins-cli.jar java -jar jenkins-cli.jar -s http://localhost:8080 install-plugin phing java -jar jenkins-cli.jar -s http://localhost:8080 install-plugin dry java -jar jenkins-cli.jar -s http://localhost:8080 install-plugin pmd java -jar jenkins-cli.jar -s http://localhost:8080 install-plugin clover java -jar jenkins-cli.jar -s http://localhost:8080 safe-restart
ジョブの設定
jenkinsの設定は ${JENKINS_HOME}以下に全てある。
各ジョブの設定は、${JENKINS_HOME}/jobs/ジョブ名/ にある。
ジョブの設定ファイル
${JENKINS_HOME}/jobs/ジョブ名/config.xml
ビルドの設定例 テストのみ(ソースコードチェックをしない)
- ビルドの保存最大数
- 5。多いと邪魔になる。
- ビルド
- Phing。 ターゲットは入力しない場合、デフォルトで build.xml を読み込む
- ビルド後の処理
- JUnitテスト結果の集計、Javadocの保存、Publish xUnit test result report、Emotional Jenkins を有効。細かい設定は、config.xml 参照
サンプルジョブ
PHP_Sample.zip(564)
ディレクトリ構成
PHP_Sample01 |-- builds |-- config.xml |-- javadoc `-- workspace |-- build.xml |-- phpdoc |-- phpunit.xml |-- src | |-- sample01.php `-- test |-- sample01Test.php
config.xml
<?xml version='1.0' encoding='UTF-8'?> <project> <actions/> <description></description> <logRotator> <daysToKeep>-1</daysToKeep> <numToKeep>5</numToKeep> <artifactDaysToKeep>-1</artifactDaysToKeep> <artifactNumToKeep>-1</artifactNumToKeep> </logRotator> <keepDependencies>false</keepDependencies> <properties/> <scm class="hudson.scm.NullSCM"/> <canRoam>true</canRoam> <disabled>false</disabled> <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding> <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding> <triggers class="vector"/> <concurrentBuild>false</concurrentBuild> <builders> <hudson.plugins.phing.PhingBuilder> <useModuleRoot>true</useModuleRoot> </hudson.plugins.phing.PhingBuilder> </builders> <publishers> <hudson.tasks.junit.JUnitResultArchiver> <testResults>phpunit.xml</testResults> <keepLongStdio>false</keepLongStdio> <testDataPublishers/> </hudson.tasks.junit.JUnitResultArchiver> <hudson.tasks.JavadocArchiver> <javadocDir>phpdoc</javadocDir> <keepAll>false</keepAll> </hudson.tasks.JavadocArchiver> <xunit> <types/> <thresholds> <org.jenkinsci.plugins.xunit.threshold.FailedThreshold> <unstableThreshold>0</unstableThreshold> <unstableNewThreshold>0</unstableNewThreshold> <failureThreshold>0</failureThreshold> <failureNewThreshold>0</failureNewThreshold> </org.jenkinsci.plugins.xunit.threshold.FailedThreshold> <org.jenkinsci.plugins.xunit.threshold.SkippedThreshold> <unstableThreshold>0</unstableThreshold> <unstableNewThreshold>0</unstableNewThreshold> <failureThreshold>0</failureThreshold> <failureNewThreshold>0</failureNewThreshold> </org.jenkinsci.plugins.xunit.threshold.SkippedThreshold> </thresholds> <thresholdMode>1</thresholdMode> </xunit> <org.jenkinsci.plugins.emotional__jenkins.EmotionalJenkinsPublisher/> </publishers> <buildWrappers/> </project>
build.xml
<?xml version="1.0" encoding="utf-8" ?> <project name="ci_workshop" basedir="." default="all"> <property name="outputDir" value="."/> <target name="phpunit"> <phpunit> <formatter type="xml" outfile="${outputDir}/phpunit.xml"/> <batchtest> <fileset dir="./test/"> <include name="**/*Test.php"/> </fileset> </batchtest> </phpunit> </target> <target name="phpdoc"> <mkdir dir="phpdoc" /> <phpdoc title="API Documentation" destdir="./phpdoc" output="HTML:Smarty:PHP"> <fileset dir="./src"> </fileset> </phpdoc> </target> <target name="all" depends="phpunit,phpdoc"> </target> </project>
ビルドの設定例2 テストとソースコードチェック
ビルド後の処理:PMD警告の集計、重複コード分析の集計。細かい設定は、config.xml 参照
サンプルジョブ
PHP_Sample2.zip(553)
ディレクトリ構成
PHP_Sample02 |-- builds |-- config.xml |-- javadoc `-- workspace |-- build.xml |-- cpd.xml |-- phpdoc |-- phpunit.xml |-- pmd.xml |-- ruleset.xml |-- src | |-- sample01.php | `-- sample02.php `-- test |-- sample01Test.php
config.xml
<?xml version='1.0' encoding='UTF-8'?> <project> <actions/> <description></description> <logRotator> <daysToKeep>-1</daysToKeep> <numToKeep>5</numToKeep> <artifactDaysToKeep>-1</artifactDaysToKeep> <artifactNumToKeep>-1</artifactNumToKeep> </logRotator> <keepDependencies>false</keepDependencies> <properties/> <scm class="hudson.scm.NullSCM"/> <canRoam>true</canRoam> <disabled>false</disabled> <blockBuildWhenDownstreamBuilding>false</blockBuildWhenDownstreamBuilding> <blockBuildWhenUpstreamBuilding>false</blockBuildWhenUpstreamBuilding> <triggers class="vector"/> <concurrentBuild>false</concurrentBuild> <builders> <hudson.plugins.phing.PhingBuilder> <useModuleRoot>true</useModuleRoot> </hudson.plugins.phing.PhingBuilder> </builders> <publishers> <hudson.plugins.pmd.PmdPublisher> <healthy></healthy> <unHealthy></unHealthy> <thresholdLimit>low</thresholdLimit> <pluginName>[PMD] </pluginName> <defaultEncoding></defaultEncoding> <canRunOnFailed>false</canRunOnFailed> <useStableBuildAsReference>false</useStableBuildAsReference> <useDeltaValues>false</useDeltaValues> <thresholds> <unstableTotalAll>0</unstableTotalAll> <unstableTotalHigh>0</unstableTotalHigh> <unstableTotalNormal>0</unstableTotalNormal> <unstableTotalLow>0</unstableTotalLow> <failedTotalAll></failedTotalAll> <failedTotalHigh></failedTotalHigh> <failedTotalNormal></failedTotalNormal> <failedTotalLow></failedTotalLow> </thresholds> <shouldDetectModules>false</shouldDetectModules> <dontComputeNew>true</dontComputeNew> <doNotResolveRelativePaths>true</doNotResolveRelativePaths> <pattern>pmd*.xml</pattern> </hudson.plugins.pmd.PmdPublisher> <hudson.plugins.dry.DryPublisher> <healthy></healthy> <unHealthy></unHealthy> <thresholdLimit>low</thresholdLimit> <pluginName>[DRY] </pluginName> <defaultEncoding></defaultEncoding> <canRunOnFailed>false</canRunOnFailed> <useStableBuildAsReference>false</useStableBuildAsReference> <useDeltaValues>false</useDeltaValues> <thresholds> <unstableTotalAll></unstableTotalAll> <unstableTotalHigh></unstableTotalHigh> <unstableTotalNormal></unstableTotalNormal> <unstableTotalLow></unstableTotalLow> <failedTotalAll></failedTotalAll> <failedTotalHigh></failedTotalHigh> <failedTotalNormal></failedTotalNormal> <failedTotalLow></failedTotalLow> </thresholds> <shouldDetectModules>false</shouldDetectModules> <dontComputeNew>true</dontComputeNew> <doNotResolveRelativePaths>false</doNotResolveRelativePaths> <pattern>cpd*.xml</pattern> <highThreshold>20</highThreshold> <normalThreshold>10</normalThreshold> </hudson.plugins.dry.DryPublisher> <hudson.tasks.junit.JUnitResultArchiver> <testResults>phpunit.xml</testResults> <keepLongStdio>false</keepLongStdio> <testDataPublishers/> </hudson.tasks.junit.JUnitResultArchiver> <hudson.tasks.JavadocArchiver> <javadocDir>phpdoc</javadocDir> <keepAll>false</keepAll> </hudson.tasks.JavadocArchiver> <xunit> <types/> <thresholds> <org.jenkinsci.plugins.xunit.threshold.FailedThreshold> <unstableThreshold>0</unstableThreshold> <unstableNewThreshold>0</unstableNewThreshold> <failureThreshold>0</failureThreshold> <failureNewThreshold>0</failureNewThreshold> </org.jenkinsci.plugins.xunit.threshold.FailedThreshold> <org.jenkinsci.plugins.xunit.threshold.SkippedThreshold> <unstableThreshold>0</unstableThreshold> <unstableNewThreshold>0</unstableNewThreshold> <failureThreshold>0</failureThreshold> <failureNewThreshold>0</failureNewThreshold> </org.jenkinsci.plugins.xunit.threshold.SkippedThreshold> </thresholds> <thresholdMode>1</thresholdMode> </xunit> <org.jenkinsci.plugins.emotional__jenkins.EmotionalJenkinsPublisher/> </publishers> <buildWrappers/> </project>
build.xml
<?xml version="1.0" encoding="utf-8" ?> <project name="ci_workshop" basedir="." default="all"> <property name="outputDir" value="."/> <target name="phpcpd"> <phpcpd minTokens="10"> <fileset dir="./src/"> <include name="**/*.php"/> </fileset> <formatter type="pmd" outfile="${outputDir}/cpd.xml"/> </phpcpd> </target> <target name="phpmd"> <phpmd rulesets="ruleset.xml"> <fileset dir="./src"> <exclude name="exclude.php"/> </fileset> <formatter type="xml" outfile="${outputDir}/pmd.xml"/> </phpmd> </target> <target name="phpunit"> <phpunit> <formatter type="xml" outfile="${outputDir}/phpunit.xml"/> <batchtest> <fileset dir="./test/"> <include name="**/*Test.php"/> </fileset> </batchtest> </phpunit> </target> <target name="phpdoc"> <mkdir dir="phpdoc" /> <phpdoc title="API Documentation" destdir="./phpdoc" output="HTML:Smarty:PHP"> <fileset dir="./src"> </fileset> </phpdoc> </target> <target name="all" depends="phpcpd,phpmd,phpunit,phpdoc"> </target> </project>
ruleset.xml コードチェックのルール
<?xml version="1.0"?> <ruleset name="Hyper mANAGE PHPMD ruleset" xmlns="http://pmd.sf.net/ruleset/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd" xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd"> <rule ref="rulesets/codesize.xml" /> <rule ref="rulesets/design.xml" /> <rule ref="rulesets/naming.xml"> <exclude name="ShortVariable" /> <exclude name="LongVariable" /> </rule> <rule ref="rulesets/unusedcode.xml" /> </ruleset>
[カテゴリ: ツール > 開発]
[カテゴリ: プログラミング言語 > PHP]
[通知用URL]
Tweet
最終更新時間:2013年06月30日 19時25分46秒