Jenkinsを拡張したい
前の日記で書いた内容の機能をJenkinsの拡張プラグインとして
作成するためには、その方法を知らなければなりません。(公開まで遠い道のりになりそうです。。。)
幸い方法は、ここに書かれています。
基本はこの通りに行っていくわけですが、うまく動かなかったところがあったので、ここに残しておきたいと思います。
まず、mavenのsettings.xmlにプラグイングループ(org.jenkins-ci.tools)を追加します。
<settings> <pluginGroups> <pluginGroup>org.jenkins-ci.tools</pluginGroup> </pluginGroups> </settings>
さらに、追加ステップとしてプロファイルの追加も行います。
<settings> <profiles> <profile> <id>jenkins</id> <repositories> <repository> <id>m.g.o-public</id> <url>http://maven.glassfish.org/content/groups/public/</url> </repository> </repositories> </profile> </profiles> <activeProfiles> <activeProfile>jenkins</activeProfile> </activeProfiles> </settings>
この後、mvn -cpu hpi:createを実行するのですが、ここで以下のようなエラーが出てはまりました。
C:\home\jenkins>mvn -cpu hpi:create [INFO] Scanning for projects... [INFO] Searching repository for plugin with prefix: 'hpi'. [INFO] ------------------------------------------------------------------------ [ERROR] BUILD ERROR [INFO] ------------------------------------------------------------------------ [INFO] The plugin 'org.apache.maven.plugins:maven-hpi-plugin' does not exist or no valid version could be found [INFO] ------------------------------------------------------------------------ [INFO] For more information, run Maven with the -e switch [INFO] ------------------------------------------------------------------------ [INFO] Total time: < 1 second [INFO] Finished at: Fri Mar 11 12:56:29 JST 2011 [INFO] Final Memory: 2M/247M [INFO] ------------------------------------------------------------------------ C:\home\jenkins>
悩んだ挙句、「pluginRepositoriesを追加しないと検索してくれないのでは?」と思い、プロファイルに追加したリポジトリと
同じURLをpluginRepositoriesとしても登録しました。
↓
<?xml version="1.0" encoding="UTF-8"?> <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"> <pluginGroups> <pluginGroup>org.jenkins-ci.tools</pluginGroup> </pluginGroups> <profiles> <profile> <id>jenkins</id> <repositories> <repository> <id>m.g.o-public</id> <url>http://maven.glassfish.org/content/groups/public/</url> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>m.g.o-public</id> <url>http://maven.glassfish.org/content/groups/public/</url> </pluginRepository> </pluginRepositories> </profile> </profiles> <activeProfiles> <activeProfile>jenkins</activeProfile> </activeProfiles> </settings>
すると今度はうまくいきました。
途中で、groupIdとartifactIdを聞かれますので、適当に入力して進めます。
(ここでは、groupId:sample, artifactId:SampleModuleと入力しています。)
ここから先は特につまるところが無かったです。
作成されたディレクトリに移動し、mvn packageやmvn installも問題なく成功しました。
ちなみに、作成されたディレクトリ(図の例では、SampleModule)の直下にあるpom.xmlの中の
Jenkinsのターゲットバージョンを変更できます。
普段eclipseを使用しているので、eclipseのプロジェクトを作成しました。
cd SampleModule mvn package mvn install mvn -DdownloadSources=true -DdownloadJavadocs=true -DoutputDirectory=target/eclipse-classes eclipse:eclipse
次にデバッグですが、これも期待通りの動きで問題ありませんでした。
set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=8000,suspend=n mvn hpi:run
上のように実行すると、デバックポート8000、Httpアクセス8080でデバック環境が起動します。
eclipseでのリモートデバッグの設定は、デバックの構成からリモートJavaアプリケーションで行います。
mvn -cpu hpi:createで作成したプロジェクトには、HelloWorldBuilderというサンプルがついていますので、
これを利用してデバッグできるか試してみます。
新規ジョブを作成します。ビルドの追加で、HelloWorldBuilderにより実装されている「Say hello world」という
名前のビルダーを指定します。
ビルドの実行時に止めてみたいので、HelloWorldBuilderのperformメソッドで適当にデバッグポイントを設定してみます。
準備ができたら、先ほどのジョブを実行してみます。
実行するとすぐに、eclipseのデバッグパースペクティブが起動してきました。
これでJenkinsの拡張開発に必要な最低限の環境が整ったことになります。
あとは実装するのですが、まだまだ勉強しないと着手できそうにありません。
ファイルI/Fの機能を実装できるのはいつの日になるのやら。。。。