JenkinsでGithubのWebHookを使って自動テストする。
### Jenkinsに「Jenkins GIT plugin」が導入済
### Jenkinsユーザーの公開鍵がGithubに登録されていることが前提です。
### また、その他必要なプラグインなどは各自揃えて下さい。
===============================
### テスト対象として一つ前の記事
「JenkinsでPHPUnitを実行するだけのためのbuild.xml (Apache Ant)。」を使います。
> Github サンプルコード
===============================
### Jenkinsで「新規ジョブ作成」を作成します。
- ・「ジョブ名」
- ・「フリースタイル・プロジェクトのビルド」を選択します。
===============================
### 「ジョブの設定」を編集します。
- ・「ソースコード管理」
===============================
- ・「ビルド・トリガ」
- 「SCMをポーリング」を選択します。
- ・「ビルド環境」
- ・「ビルド」
- 「Antの呼び出し」を選択して「使用するAnt」を選びます。
- ・「保存」する
===============================
Githubリポジトリの[Settings] => [Service Hooks] => [Jenkins (Git plugin)]
- ・「Jenkins Url」を入力(以下参照)します。
- ・「Active」を選択します。
- ・「Update settings」を選択します。
# Jenkins Basic認証なし http://hostname.com/git/notifyCommit?url=git@github.com:tuki0918/jenkins_phpunit.git # Jenkins Basic認証あり http://username:password@hostname.com/git/notifyCommit?url=git@github.com:tuki0918/jenkins_phpunit.git
===============================
### Jenkinsに通知テスト
- ・「Test Hook」を選択します。
- ・Jenkins側でテストが実行されていれば成功です。
===============================
### GithubにPushしてみる
- ・Githubに「Push」します。
- ・Jenkins側でテストが実行されていれば成功です。
お疲れ様でした。
===============================
### はまりポイント
- ・build時にコマンドがないよーって言われることがある。
- [Jenkinsの管理] => [ステムの設定] => [グローバル プロパティ]にパスを設定してあげるといけた模様。
- ・「環境変数」を選択します。
キー:PATH 値 :${PATH}:/usr/local/bin
JenkinsでPHPUnitを実行するだけのためのbuild.xml (Apache Ant)。
JenkinsでPHPUnitのテストを走らせるためだけのbuild.xmlです。
「tests」フォルダ以下の「*Test.php」のテストスイートを実行します。
> tuki0918/jenkins_phpunit サンプルコード
### フォルダ階層
workspace │ ├── build.xml └── tests ├── sample1Test.php ├── sample2Test.php └── sample3Test.php
### build.xml
<project name="jenkins project" default="build"> <target name="phpunit"> <exec dir="." executable="phpunit" failonerror="true"> <arg line="--colors tests" /> </exec> </target> <target name="build" depends="phpunit"/> </project>
### tests/sample1Test.php
<?php class UnitTest extends PHPUnit_Framework_TestCase { public function testPushAndPop() { $user = array(); $this->assertEquals(0, count($user)); array_push($user, 'hoge'); $this->assertEquals('hoge', $user[0]); $this->assertEquals(1, count($user)); $this->assertEquals('hoge', array_pop($user)); $this->assertEquals(0, count($user)); } public function testArray() { $array = array(); $this->assertEquals(0, count($array)); } }
### テスト成功時
### テスト失敗時
### コンソール出力のカラー変更
AnsiColorプラグイン