phpcs/phpmd/phpcpdをJenkinsで試してみる
phpcs/phpmd/phpcpd/phpdcd/phplocをインストールしてみる
の続き
phpcs/phpmd/phpcpdをJenkinsで試してみる。
【参考】 jenkinsでCheckstyle pluginを利用して、CakePHPのコーディング規約をチェックする | ミラボ http://log.miraoto.com/2012/04/510/
Jenkinsのインストール
まずはJenkinsをインストールする。
とりあえずrootになって、javaなど入れておく。
$ su -
# yum -y install java-1.7.0-openjdk wget
Jenkinsをインストールする。
# wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo # rpm --import http://pkg.jenkins-ci.org/redhat/jenkins-ci.org.key # yum -y install jenkins
起動する。自動起動の設定もしておく。
# service jenkins start # chkconfig jenkins on
以上で、
http://サーバーのIPアドレス:8080/
にアクセスするとJenkinsが表示される。
Phingのインストール
ビルドするのに必要とのことなので入れる。
# pear install phing/phing
# pear channel-discover pear.phing.info は前回の記事で実施済み
Jenkinsプラグインのインストール
[Jenkinsの管理]-[プラグインの管理]-[利用可能]タブ
を開く。
下記の4つのプラグインをインストーする。
・Phing plugin
・Checkstyle Plug-in ※phpcs用
・PMD Plugin ※phpmd用
・DRY Plugin ※phpcpd用
build.xmlの作成
build.xmlを作成する。
とりあえず、/tmpにでも置いておく。
前回試しに使ったサンプルプログラムは/tmp/sampleにあり、
こちらを解析対象としている。
$ vi /tmp/build.xml
<?xml version="1.0" encoding="utf-8" ?> <project name= "BuildTest" basedir= "." default= "main"> <target name="main" depends= "init,phpcs,phpmd,phpcpd"></target> <!-- init --> <target name="init"> <delete dir= "./reports" includeemptydirs= "true" /> <mkdir dir= "./reports" /> </target> <!-- phpcs --> <target name="phpcs"> <exec executable= "phpcs" output= "reports/phpcs.xml"> <arg line= "--report=checkstyle /tmp/sample" /> </exec> </target> <!-- phpmd --> <target name="phpmd"> <phpmd rulesets= "cleancode,codesize,controversial,design,naming,unusedcode"> <fileset dir= "/tmp/sample"> <include name= "**/*.php" /> <exclude name= "**/*Test.php" /> </fileset> <formatter type= "xml" outfile= "reports/phpmd.xml" /> </phpmd> </target> <!-- phpcpd --> <target name="phpcpd"> <phpcpd> <fileset dir= "/tmp/sample"> <include name= "**/*.php" /> <exclude name= "**/*Test.php" /> </fileset> <formatter type= "pmd" outfile= "reports/phpcpd.xml" /> </phpcpd> </target> </project>
ジョブの作成
Jenkins上で新しいジョブを作成する。
ジョブ名は適当に入力し、「フリースタイル・プロジェクトのビルド」を選択する。
ビルド手順の追加
「Phingの呼び出し」を追加する。
ビルドファイルには「/tmp/build.xml」を指定する。
ビルド後の処理の追加
「Checkstyle警告の集計」を追加する。
集計するファイルには「reports/phpcs.xml」を指定する。
「PMD警告の集計」を追加する。
集計するファイルには「reports/phpmd.xml」を指定する。
「重複コードの分析の集計」を追加する。
集計するファイルには「reports/phpcpd.xml」を指定する。