Jenkinsメモ
****************

OSXへのインストール
===========================

http://qiita.com/makoto_kw/items/cbe93d4ebbc35f3b43fd
を参考にした。

::
 
 brew install jenkins
 cp -p /usr/local/opt/jenkins/*.plist ~/Library/LaunchAgents
 vi ~/Library/LaunchAgents/homebrew.mxcl.jenkins.plist 
 launchctl load ~/Library/LaunchAgents/homebrew.mxcl.jenkins.plist
 launchctl start homebrew.mxcl.jenkins
 # launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.jenkins.plist
 # launchctl stop homebrew.mxcl.jenkins

APIテストを作成してみる
=================================

概要
-------

ここではWeb API開発を前提としてテストを作成する。

http://tech.albert2005.co.jp/blog/2014/07/10/notify-hipchat-from-jenkins/

をみるのが良さそう。

WebAPIの作成
----------------

.. literalinclude:: Src/json_add.py
  :language: python
  :linenos:

みたいなコードを作成した。

::
 
 # curl -H "Content-Type:application/json" -X POST -d '{"val1": 1, "val2": 2}' http://localhost:5000/add  
 <hr>3<hr>

のようにテストできる。

で、Flaskアプリ化したいので、

.. literalinclude:: Src/json_add.wsgi
  :language: python
  :linenos:

を書いて、

::

 WSGIDaemonProcess  user=nobody group=nogroup threads=5
 WSGIScriptReloading On
 WSGIScriptAlias /calc /home/kanai/git/PythonJunkTest/Flask/json_add.wsgi

みたいに書いてあげる。
すると、

::

 curl -H "Content-Type:application/json" -X POST -d '{"val1": 1, "val2": 1}' http://www.hogetan.net/calc/add

みたいに、apacheで提供できる。やったね。

テストを作る
------------------

APIができました!が目的ではなくて、テストの

Jenkinsに設定
------------------

http://tech.albert2005.co.jp/blog/2014/07/10/notify-hipchat-from-jenkins/
を最大限に使う。

::

  easy_install unittest-xml-reporting

jenkins

::

 フリースタイルプロジェクト
 ソースコード管理「なし」
 シェルスクリプトにして、
 cd /Users/kanai/git/PythonJunkTest/Flask/Test_json_add
 /usr/local/bin/nosetests --with-xunit -v

という感じで作る。これで上記のディレクトリに
nosetests.xmlが生成されて、その結果を基にテストが行われる。