ページ

2015年5月31日日曜日

Chefでお料理 2 - GitLab + Jenkins -

今回から「Gitlab + Jenkins環境構築のCookbookを作成」を目指して頑張ってみる


・saharaプラグインのインストール

chefを何度も実行しながらテストするので、ロールバック的な機能がvagrantにあれば
非常に助かる。と思っていたらそんなプラグインがありました。
sahara」いうらしい。

↓公式ページ
https://github.com/jedi4ever/sahara

↓使い方など
http://easyramble.com/install-sahara-into-vagrant.html

ロールバックや、コミットなどができて便利。早速インストール!!
$ vagrant plugin list
vagrant-berkshelf (4.0.4)
vagrant-omnibus (1.4.1)
vagrant-share (1.1.3, system)
$ vagrant plugin install sahara
Installing the 'sahara' plugin. This can take a few minutes...
Installed the plugin 'sahara (0.0.17)'!
$ vagrant plugin list
sahara (0.0.17)
vagrant-berkshelf (4.0.4)
vagrant-omnibus (1.4.1)
vagrant-share (1.1.3, system)

・vagrant plugin list
 現在のプラグインインストール状況をリスト表示

・vagrant plugin install sahara
    saharaプラグインのインストール

環境構築用にVMを作成。
$ mkdir shipmerry
$ ls
shipmerry
$ cd shipmerry/
$ ls
$ vagrant box list
centos6  (virtualbox, 0)
jenkins  (virtualbox, 0)
ubuntu14 (virtualbox, 0)
$ vagrant init centos6
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.
$ vagrant up


ディレクトリの名前は「shipmerry」IPアドレスは以下に設定しました
config.vm.network "private_network", ip: "192.168.55.35"

そうです。ワンピースのゴーイングメリー号です。。


saharaのスナップショットを取るモードに変更
$ vagrant sandbox on
[default] Starting sandbox mode...
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%

sshのホスト設定
vagrant ssh-config --host merry >> ~/.ssh/config


・最初にJDKをインストールするレシピを作成する。

$ knife cookbook create jdk -o site-cookbooks
** Creating cookbook jdk in /Users/ユーザ名/Documents/develop/vagrant/boxes/shipmerry/chef-repo/site-cookbooks
** Creating README for cookbook: jdk
** Creating CHANGELOG for cookbook: jdk
** Creating metadata for cookbook: jdk

↓レシピのないよう

# JDKインストール
case node['platform_family']
when 'debian'
  package 'openjdk-7-jdk'
when 'rhel'
  package 'java-1.7.0-openjdk'
else
  fail "`#{node['platform_family']}' is not supported!"
end

# JAVA_HOME環境変数を設定
cookbook_file "profile-java.sh" do
  path "/etc/profile.d/java.sh"
end
~     


・case node[‘platform_family’]
プラットフォーム毎に処理を切り分ける。
http://qiita.com/DQNEO/items/b8b808394ca08a2a86f9

・cookbook_fileでファイルを配置
↓profile-java.shの中身
shipmerry/chef-repo/site-cookbooks/jdk/files/default/profile-java.sh
JAVA_PATH=`readlink -m $(which java)`
export JAVA_HOME=${JAVA_PATH%/*/*}

※readlinkでシンボリックリンクのリンク先を取ってくる。
   ${JAVA_PATH%/*/*}で2階層のパスを削除しJAVA_HOMEに設定
↓readlink
[vagrant@localhost ~]$ readlink -m $(which java)
/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.79.x86_64/jre/bin/java

↓JAVA_HOME
JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.79.x86_64/jre

参考URL
http://qiita.com/asam316/items/08fb59f1da9d78f0e1a6
http://d.hatena.ne.jp/torutk/20090628/p1


・次にAntのインストールを行うCookbookの作成

参考URL
https://github.com/opscode-cookbooks/ant

↓レシピ
#
# Cookbook Name:: ant
# Recipe:: default
#
# Copyright 2015, YOUR_COMPANY_NAME
#
# All rights reserved - Do Not Redistribute
#

ant_home = node['ant']['home']

# ファイル取得
remote_file "/tmp/ant.tar.gz" do
  source node['ant']['url']
  checksum node['ant']['checksum']
end

# 取得したファイルを解凍し移動
script "install_ant" do
  interpreter "bash"
  user "root"
  code <<-EOL
    tar zxvf /tmp/ant.tar.gz
    rm -rf "#{ant_home}"
    mv -f apache-ant-* "#{ant_home}"
  EOL
end

# 環境変数の設定
template "/etc/profile.d/ant_home.sh" do
  mode 0755
  source "ant_home.sh.erb"
  variables(:ant_home => node['ant']['home'])
end

↓実行して確認
[vagrant@localhost bin]$ ./ant -version
Unable to locate tools.jar. Expected to find it in /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.79.x86_64/lib/tools.jar
Apache Ant(TM) version 1.8.2 compiled on December 20 2010

ん?tools.jarがないと怒られている・・・
vagrant@localhost bin]$ cd /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.79.x86_64/
[vagrant@localhost java-1.7.0-openjdk-1.7.0.79.x86_64]$ ls
ASSEMBLY_EXCEPTION  LICENSE  THIRD_PARTY_README  jre
[vagrant@localhost java-1.7.0-openjdk-1.7.0.79.x86_64]$ cd jre/
[vagrant@localhost jre]$ ls
bin  lib
[vagrant@localhost jre]$ cd bin
[vagrant@localhost bin]$ ls
java     orbd     policytool  rmiregistry  tnameserv
keytool  pack200  rmid        servertool   unpack200
[vagrant@localhost bin]$ cd ../
[vagrant@localhost jre]$ ls
bin  lib
[vagrant@localhost jre]$ cd lib
[vagrant@localhost lib]$ ls
accessibility.properties  flavormap.properties  psfont.properties.ja
amd64                     images                psfontj2d.properties
applet                    jce.jar               resources.jar
audio                     jexec                 rhino.jar
calendars.properties      jsse.jar              rt.jar
charsets.jar              jvm.hprof.txt         security
classlist                 logging.properties    sound.properties
cmm                       management            tz.properties
content-types.properties  management-agent.jar  zi
currency.data             meta-index
ext                       net.properties

実際ない><;
このJDKじゃダメじゃんorz

そういう事でJDKのCookbookを修正。
#
# Cookbook Name:: jdk
# Recipe:: default
#
# Copyright 2015, YOUR_COMPANY_NAME
#
# All rights reserved - Do Not Redistribute
#

# JDKインストール
#case node['platform_family']
#when 'debian'
#  package 'openjdk-7-jdk'
#when 'rhel'
#  package 'java-1.7.0-openjdk'
#else
#  fail "`#{node['platform_family']}' is not supported!"
#end

cookbook_file node['jdk']['file']  do
  path "/tmp/jdk-linux-x64.tar"
end

script "install_jdk" do
  interpreter "bash"
  user "root"
  code <<-EOL
    tar xvf /tmp/jdk-linux-x64.tar
    mv -f /jdk* /usr/local/jdk
    rm /usr/bin/java
    rm /usr/bin/javac
    ln -s /usr/local/jdk/bin/java /usr/bin/java
    ln -s /usr/local/jdk/bin/javac /usr/bin/javac
  EOL
end

# JAVA_HOME環境変数を設定
cookbook_file "profile-java.sh" do
  path "/etc/profile.d/java.sh"
end

↓改めて実行!!
i$ knife solo cook merry
Running Chef on merry...
Checking Chef version...
Installing Berkshelf cookbooks to 'cookbooks'...
DEPRECATED: Your Berksfile contains a site location pointing to the Opscode Community Site (site :opscode). Site locations have been replaced by the source location. Change this to: 'source "https://supermarket.chef.io"' to remove this warning. For more information visit https://github.com/berkshelf/berkshelf/wiki/deprecated-locations
Resolving cookbook dependencies...
Uploading the kitchen...
WARNING: Local cookbook_path '/Users/ユーザ名/Documents/develop/vagrant/boxes/shipmerry/chef-repo/cookbooks' does not exist
Generating solo config...
Running Chef...
Starting Chef Client, version 12.3.0
Compiling Cookbooks...
Converging 6 resources
Recipe: jdk::default
  * cookbook_file[jdk-7u79-linux-x64.tar] action create
    - create new file /tmp/jdk-linux-x64.tar
    - update content in file /tmp/jdk-linux-x64.tar from none to 084d1d
    (file sizes exceed 10000000 bytes, diff output suppressed)
  * script[install_jdk] action run
    - execute "bash"  "/tmp/chef-script20150531-2983-sepjz6"
  * cookbook_file[profile-java.sh] action create
    - create new file /etc/profile.d/java.sh
    - update content in file /etc/profile.d/java.sh from none to 09fb37
    --- /etc/profile.d/java.sh 2015-05-31 09:24:14.085580102 +0000
    +++ /etc/profile.d/.profile-java.sh20150531-2983-zepb85 2015-05-31 09:24:14.085580102 +0000
    @@ -1 +1,3 @@
    +JAVA_PATH=`readlink -m $(which java)`
    +export JAVA_HOME=${JAVA_PATH%/*/*}
Recipe: ant::default
  * remote_file[/tmp/ant.tar.gz] action create
    - create new file /tmp/ant.tar.gz
    - update content in file /tmp/ant.tar.gz from none to 664f48
    (new content is binary, diff output suppressed)
  * script[install_ant] action run
    - execute "bash"  "/tmp/chef-script20150531-2983-k8fmyi"
  * template[/etc/profile.d/ant_home.sh] action create
    - create new file /etc/profile.d/ant_home.sh
    - update content in file /etc/profile.d/ant_home.sh from none to cef22d
    --- /etc/profile.d/ant_home.sh 2015-05-31 09:24:35.433248587 +0000
    +++ /tmp/chef-rendered-template20150531-2983-cv3gg2 2015-05-31 09:24:35.433248587 +0000
    @@ -1 +1,4 @@
    +export ANT_HOME=/usr/local/ant
    +PATH=$PATH:/usr/local/ant/bin
    +export PATH
    - change mode from '' to '0755'

Running handlers:
Running handlers complete
Chef Client finished, 6/6 resources updated in 44.699034477 seconds


↓確認
$ ssh merry
Last login: Sun May 31 09:23:48 2015 from 10.0.2.2
Welcome to your Vagrant-built virtual machine.
[vagrant@localhost ~]$ which java
/usr/bin/java
[vagrant@localhost ~]$ which javac
/usr/bin/javac
[vagrant@localhost ~]$ ant
Buildfile: build.xml does not exist!
Build failed
[vagrant@localhost ~]$ 

ちゃんとインストールされている〜^^

2015年5月30日土曜日

Chefでお料理 1 - ChefServer/ChefClint -

前回新しいい技術で勉強して、ちゃんと覚えれば役に立ちそうなので、
このまま使うように頑張ってみる。。


しかしこのChefやたら用語が沢山あってわかりづらいorz
一応整理すると・・・

使い方として大きく2種類ある。
  1. ChefServerを立てる
  2. スタンドアロン

個人でやるだけならChefServerを立てるまでもないので、スタンドアロンでやる。
スタンドアロンでやる時に使うツールが「Chef-solo」
そしてnodeにChef-Clientをインストールするなど便利なツールとして「Knife-solo」がある

↓現在インストールされているバージョン
$ chef-solo -v
Chef: 12.3.0


んで自分でCookbookを作る時には「site-cookbooks」配下に作っていく。
ベンダー製のCookBookを使えたりもする。

ベンダー製のCookBookを使う場合Berkshelfが便利。Rubyでいう所のBundler
使い方が掲載されたサイトを見て使ってみたがどうやら古いらしい。。
以下のサイトを発見!!
http://qiita.com/wwacky/items/66b493a05c99b5e754e8

・Berksfileの中身
site :opscode
cookbook 'java', '~> 1.31.0'
~                               

・コマンド実行!!
$ berks install
DEPRECATED: Your Berksfile contains a site location pointing to the Opscode Community Site (site :opscode). Site locations have been replaced by the source location. Change this to: 'source "https://supermarket.chef.io"' to remove this warning. For more information visit https://github.com/berkshelf/berkshelf/wiki/deprecated-locations
Resolving cookbook dependencies...
Fetching cookbook index from https://supermarket.chef.io...
Installing java (1.31.0)


$ berks vendor
DEPRECATED: Your Berksfile contains a site location pointing to the Opscode Community Site (site :opscode). Site locations have been replaced by the source location. Change this to: 'source "https://supermarket.chef.io"' to remove this warning. For more information visit https://github.com/berkshelf/berkshelf/wiki/deprecated-locations
Resolving cookbook dependencies...
Using java (1.31.0)
Vendoring java (1.31.0) to /Users/{ユーザ名}/Documents/develop/vagrant/boxes/cheftest/chef-repo/berks-cookbooks/java

・node.jsonの中身
{
  "run_list": [
     "java"
  ],
  "automatic": {
    "ipaddress": "chopper"
  }
}
~

・いざ実行!!
$ knife solo cook chopper
Running Chef on chopper...
Checking Chef version...
Installing Berkshelf cookbooks to 'cookbooks'...
DEPRECATED: Your Berksfile contains a site location pointing to the Opscode Community Site (site :opscode). Site locations have been replaced by the source location. Change this to: 'source "https://supermarket.chef.io"' to remove this warning. For more information visit https://github.com/berkshelf/berkshelf/wiki/deprecated-locations
Resolving cookbook dependencies...
Using java (1.31.0)
Vendoring java (1.31.0) to cookbooks/java
Uploading the kitchen...
Generating solo config...
Running Chef...
Starting Chef Client, version 12.3.0
Compiling Cookbooks...
Converging 6 resources
Recipe: java::openjdk
  * yum_package[java-1.6.0-openjdk] action install
    - install version 1.6.0.35-1.13.7.1.el6_6 of package java-1.6.0-openjdk
  * yum_package[java-1.6.0-openjdk-devel] action install
    - install version 1.6.0.35-1.13.7.1.el6_6 of package java-1.6.0-openjdk-devel
  * java_alternatives[set-java-alternatives] action set
    - Add alternative for appletviewer
    - Add alternative for apt
    - Add alternative for extcheck
    - Add alternative for idlj
    - Add alternative for jar
    - Add alternative for jarsigner
    - Add alternative for java
    - Add alternative for javac
    - Add alternative for javadoc
    - Add alternative for javah
    - Add alternative for javap
    - Add alternative for jconsole
    - Add alternative for jdb
    - Add alternative for jhat
    - Add alternative for jinfo
    - Add alternative for jmap
    - Add alternative for jps
    - Add alternative for jrunscript
    - Add alternative for jsadebugd
    - Add alternative for jstack
    - Add alternative for jstat
    - Add alternative for jstatd
    - Add alternative for keytool
    - Add alternative for native2ascii
    - Add alternative for orbd
    - Add alternative for pack200
    - Add alternative for policytool
    - Add alternative for rmic
    - Add alternative for rmid
    - Add alternative for rmiregistry
    - Add alternative for schemagen
    - Add alternative for serialver
    - Add alternative for servertool
    - Add alternative for tnameserv
    - Add alternative for unpack200
    - Add alternative for wsgen
    - Add alternative for wsimport
    - Add alternative for xjc
Recipe: java::set_java_home
  * ruby_block[set-env-java-home] action run
    - execute the ruby block set-env-java-home
  * directory[/etc/profile.d] action create (up to date)
  * file[/etc/profile.d/jdk.sh] action create
    - create new file /etc/profile.d/jdk.sh
    - update content in file /etc/profile.d/jdk.sh from none to 311825
    --- /etc/profile.d/jdk.sh 2015-05-30 08:08:03.326817968 +0000
    +++ /etc/profile.d/.jdk.sh20150530-6022-1r7hm6j 2015-05-30 08:08:03.326817968 +0000
    @@ -1 +1,2 @@
    +export JAVA_HOME=/usr/lib/jvm/java-1.6.0
    - change mode from '' to '0755'

Running handlers:
Running handlers complete
Chef Client finished, 5/6 resources updated in 76.980799379 seconds

・確認
$ ssh chopper
Last login: Sat May 30 08:06:45 2015 from 10.0.2.2
Welcome to your Vagrant-built virtual machine.
[vagrant@localhost ~]$ java -version
java version "1.6.0_35"


↓サードパティーのCookbookがあるサイト
https://supermarket.chef.io/cookbooks-directory

↓参考にしたサイト
http://kimikimi714.hatenablog.com/entry/2014/01/13/サードパーティ製chefレシピ使ってたの忘れてた
https://docs.chef.io/index.html#cookbooks
http://thinkit.co.jp/story/2013/11/18/4679



Antをちゃんと学ぶ

分かってるようで分かってない「Ant」をちゃんと学ぶ


Antとは・・
  Jakartaプロジェクトで開発されているJavaベースのビルドツール。

・インストールの際に設定しておいた方が良い環境変数

  • ANT_HOME  : Antがインストールされているディレクトリ
  • JAVA_HOME : JDKがインストールされているディレクトリ
  • PATH : Antの実行ファイルの場所を追加


・Antの実行

↓Antの書式  
ant [options] [target [target2 [target3] ...]]
Options:
  -help, -h              ヘルプメッセージを表示します
  -projecthelp, -p       プロジェクトに関する情報を表示します
  -version                Antのバージョンを表示します
  -diagnostics           診断や問題のレポートに役立つ情報を表示します
  -quiet, -q             なるべくメッセージを表示しないでビルドします
  -verbose, -v           詳細な進行状況を表示しながらビルドします
  -debug, -d             デバッグ情報を表示します
  -emacs, -e             装飾なしのログ情報を生成します
  -lib <path>            jarやクラスを検索するパスを指定します
  -logfile <file>        ログを出力するファイルを指定します
    -l     <file>                ''
  -logger <classname>    ログを実行するクラスを指定します
  -listener <classname>  指定したクラスのインスタンスをプロジェクトリスナとして追加します
  -noinput               対話的入力を許可しません
  -buildfile <file>      ビルドファイル名を指定します
    -file    <file>              ''
    -f       <file>              ''
  -D<property>=<value>   プロパティー値を設定します
  -keep-going, -k        失敗したターゲット(複数)に依存しないターゲットを全て実行します
  -propertyfile <name>   全てのプロパティーをファイルからロードします。
                         -Dで指定したプロパティーより優先されます
  -inputhandler <class>  入力リクエストを扱うクラスを指定します
  -find <file>           親ディレクトリを順にたどってビルドファイルを探します
    -s  <file>                   ''
  -nice  number          スレッドの優先順位を指定します
                         1 (低) ~ 10 (高); デフォルト:5 
  -nouserlib             ${user.home}/.ant/lib にあるJARファイルを参照せずに
                         Antを実行します
  -noclasspath           CLASSPATHを参照せずにAntを実行します
  -autoproxy             (Java1.5以上) OSのプロキシ設定を利用します
  -main <class>          Antのノーマルエントリポイントを上書きします
単に「ant」を叩くとカレントディレクトリのbuild.xmlを実行しようとする。
build.xmlを指定する場合は「-buildfile」オプションが必要

・ビルドファイルの構成

大きく分けて「プロジェクト」「ターゲット」「タスク」が必要

例)
<project name="sample_project" default="compile" basedir=".">
  <property name="srcdir" value="./src">
 <target name="compile">
    <!-- ここにコンパイルを実行するタスクを記述 -->
  </target>
  <target name="install" depends="compile">
    <!-- ここにインストールを実行するタスクを記述-->
  </target>
</project>


組み込みプロパティについて
プロパティ名プロパティ値
basedirproject要素のbasedir属性で設定されているベースディレクトリの絶対パス
ant.fileビルドファイルの絶対パス
ant.versionAntのバージョン
ant.project.name現在実行しているプロジェクトの名前
ant.java.versionJava仮想マシンのバージョン
※そのたJavaのSystem.getProperty()メソッドで取得できるプロパティも全て
   組み込みプロパティとして利用可能  例) ${os.name}


ターゲット
属性名説明
必須
nameターゲットの名前。
dependsこのターゲットを実行する前に必ず実行しなければいけないターゲット。カンマで区切って複数指定することができます。
 
ifこのターゲットを実行するために設定されてなければいけないプロパティの名前。もしここで指定したプロパティに何も値が設定されていなければ、ターゲットのタスクは実行はされません。
 
unlessこのターゲットを実行するために設定されていてはいけないプロパティの名前。もしここで指定したプロパティに何か値が設定されていれば、ターゲットのタスクは実行されません。
 
descriptionこのターゲットの機能の簡単な説明。Ant を -projecthelp オプションで起動したときに、ここで指定した説明が表示されます。
 

赤字・・よく使う


・データ構造

データ構造の種類
データ構造説明
Filelistファイル名を列挙することで表現するファイルの集合です。
Filesetパターンやセレクタ等を用いて選択されるファイルの集合です。
Patternsetパターンの集合を表します。
パス類似構造PATHやCLASSPATHを指定するために用いられます。
リソースファイルまたはファイルに似たものを抽象化した概念です。
リソースコレクションリソースの集合です。バージョン1.8以降、FileListなど従来のデータ構造はリソースコレクションの一種という扱いになりました
セレクタFilesetにおいて、ファイル名以外の基準でファイルの集合を選択する場合に用いられます。

パターンセット(PatternSet)
属性名説明必須
includes
集合に含めたい名前のパターン。コンマ区切りまたはスペース区切りで複数のパターンを記述することができます。省略時はすべてのファイルが含まれたとみなされます。
 
includesfile
集合に含めたい名前のパターンを記述したファイル。 
excludes
集合から除外したい名前のパターン。コンマ区切りまたはスペース区切りで複数のパターンを記述することができます。省略時は何も除外されません。 
excludesfile
集合から除外したい名前のパターンを記述したファイル。 
refid
別の場所で定義されたパターンセットを参照するときに用います。参照されるパターンセットは、id属性で名前が定義されていなければいけません。(この表にはid属性を書いていませんが、id属性はすべてのデータ構造要素で用いることができます。) 

ファイルセット(FileSet)
属性名説明初期値必須
dir
ファイル集合のベースディレクトリです。
 
defaultexcludes
デフォルト除外集合をファイル集合から除外するかどうかを指定します。
yes
 
includes
FileSetに含めたいファイルのパターン。
 
 
includesfile
FileSetに含めたいファイルのパターンを記述したファイル。
 
 
excludes
FileSetから除外したいファイルのパターン。
 
 
excludesfile
FileSetから除外したいファイルのパターンを記述したファイル。
 
 
casesensitive
英文字の大文字と小文字を区別するかどうかを指定します。
true
 
followsymlinks
シンボリックリンクをたどるかどうかを指定します。
true
 

・実際にbuild.xmlを書いてみる。

<?xml version="1.0" encoding="UTF-8" ?>
<project name="AntSample" default="release" basedir=".">

    <!-- メインのビルド関連プロパティ -->
    <property name="src" location="${basedir}/src"/>
    <property name="build" location="${basedir}/build"/>

    <!-- テストのビルド関連プロパティ -->
    <property name="test.src" location="${basedir}/test"/>
    <property name="test.build" location="${basedir}/test_build"/>
    <property name="test.report" value="${basedir}/report"/>

    <!-- テスト用クラスパス -->
    <path id="test.classpath">
        <pathelement location="${build}" />
        <pathelement location="${test.build}" />
        <pathelement location="lib/junit.jar" />
    <pathelement location="lib/org.hamcrest.core_1.3.0.v201303031735.jar" />
    </path>

    <!-- 初期化 -->
    <target name="init">
        <!-- Create the time stamp -->
        <tstamp/>
        <mkdir dir="${build}"/>
        <mkdir dir="${test.build}"/>
    <mkdir dir="${test.report}"/>
    </target>

    <!-- コンパイル -->
    <target name="compile" depends="init" description="compile the source " >
        <!-- メインをコンパイル -->
        <javac srcdir="${src}" destdir="${build}" includeAntRuntime="no"/>

        <!-- テストをコンパイル -->
        <javac srcdir="${test.src}" destdir="${test.build}" includeAntRuntime="no">
            <classpath refid="test.classpath" />
        </javac>

    </target>

    <!-- テスト実行 -->
    <target name="test" depends="compile" description="test the source " >

        <!-- レポートファイルを削除 -->
    <delete>
        <fileset dir="${test.report}" includes="TEST-*"/>
    </delete>

        <!-- JUnitによるテストを実行 -->
        <junit fork="yes" haltonfailure="false">
        <classpath refid="test.classpath" />
            <formatter type="xml" usefile="true" />
            <batchtest fork="yes" todir="${test.report}">
                <fileset dir="${test.src}">
                    <include name="**/*Test.java"/>
                </fileset>
           </batchtest>
        </junit>
    </target>

    <!-- リリース -->
    <target name="release" depends="test" description="generate the release files" >
    </target>

    <!-- クリーン -->
    <target name="clean" description="clean up" >
        <delete dir="${build}"/>
        <delete dir="${test.build}"/>
        <delete dir="${test.report}"/>
    </target>

</project>


上記のbuild.xmlでちゃんとビルドできることを確認^^
が、ここでめっちゃハマったポイントがっorz

プロパティでsrc, test.srcを宣言しているが、同ディレクトリでやろうとしていた為
エラーが多発してしまってました。。
また、src, test.srcにjavaファイルまでのフルパスを書いていた為、テスト時にクラスローダーでこけていました。orz
ダメな例) src = “${basedir}/src/main/java”
これでビルドすると main.java.XXXX.classではなくただのXXXX.classになってしまう。

参考URL
http://www.techscore.com/tech/Java/ApacheJakarta/Ant/index/
http://symfoware.blog68.fc2.com/blog-entry-993.html
http://dev.classmethod.jp/etc/jenkins/