技術ネタはQiitaに移りました。壁もどこぞに。

TeamCity JavaEE:war 版に BuildAgent インストール

通常、TeamCity(Windows/Mac OS X/Linux 版)では、すべてのモジュールひとつのパッケージに同梱されているため、BuildAgent のインストール作業などはとくに考慮する必要はない。

ところが、JavaEE 版では、BuildAgent のみ別でインストール必要がある。Java EE 版インストール後の BuildAgent の状態は、TeamCity 内の Agents メニューから確認でき、以下のようになっている。

There are no agents available.
Install Build Agents

MS Windows Installer
Zip file distribution for manual installation (unzip the file, specify the build agent's properties and run the executable file).
See our documentation for details.

f:id:Yoichi-KIKUCHI:20150113080217p:plain

BuildAgent のない状態では、TeamCity は役に立たないので、インストールを行っていく。案内に従いつつ試行錯誤した上での Agent インストール手順を残しておく。

環境変数 JAVA_HOME の設定

インストーラ内で使用しているようなので、済んでいなければ設定する。今回の環境では OpenJDK を yum インストールしていたので以下のように。

echo $JAVA_HOME

export JAVA_HOME=/usr/lib/jvm/java
echo $JAVA_HOME
/usr/lib/jvm/java

マニュアルインストーラの入手

画面の指示に従い、まずは zip 形式のインストーラを入手する。画面内の "Zip file distribution" リンクをコピーしておき以下のように。

$ cd ~
$ wget http://{hostname}:8080/TeamCity/update/buildAgent.zip

インストーラの展開と配置

入手したインストーラを展開しつつ、配置する。今回は /opt に配置することにした。

$ mkdir buildAgent
$ mv buildAgent.zip buildAgent
$ cd buildAgent
$ unzip buildAgent.zip
$ mv buildAgent.zip ../
$ sudo mkdir /opt/teamcity
$ sudo mv -R buildAgent /opt/teamcity/

BuildAgent のインストール

コンフィグレーションファイルを用意しつつ、BuildAgetn をインストールする。インストール自体はそう難しくないので、さくさく進む。

$ cd /opt/teamcity/buildAgent/bin
$ sudo chmod +x install.sh
$ sudo ./install.sh "http://{hostname}:8080/TeamCity/"
Installing TeamCity Agent for http://{hostname}:8080/TeamCity/
Looking for Java Runtime Environment...
Java executable is found in '/bin/..'.
Configuring the Agent's properties...
/opt/teamcity/buildAgent/bin
Starting the Agent under 'root' account...
nohup: 入力を無視し、出力を `nohup.out' に追記します
WARNING: The TeamCity Agent installed as standalone application and will not start automatically on machine reboot.

これだけ。しばらく待っていると、buildAgent/conf 配下に "buildAgent.properties" というファイルが作成され、ここにインストールされた BuildAgent の情報が記載される。

ただし、インストーラの吐いた最後の WARNING メッセージを見ても分かる通り、自動起動スクリプトを書くなどしないとサーバーの再起動ごとに都度起動してやらなければいけない。

BuildAgent 起動後は TeamCity の Agents メニューから、インストールされたエージェントを確認できるようになる。

f:id:Yoichi-KIKUCHI:20150113080235p:plain