LoginSignup
68
66

More than 5 years have passed since last update.

Jenkinsプラグインを開発する

Last updated at Posted at 2013-10-21

Jenkinsプラグインを開発する

Jenkinsプラグインの開発〜ビルド〜インストールまでの手順をまとめました。
主に参考にしたのはここです。→https://wiki.jenkins-ci.org/display/JA/Plugin+tutorial

1. 前準備

mavenをインストールする

私はバージョン3.1.1を使いました。
古いバージョンだと開発での手順が増えるので、バージョンは最新を使った方が良いです。

Mavenのsetting.xml(apache-maven-3.1.1/conf/setting.xml)に下記を追記する

<pluginGroups>
  <pluginGroup>org.jenkins-ci.tools</pluginGroup>
</pluginGroups>

<profiles>
  <profile>
    <id>jenkins</id>
    <activation>
      <activeByDefault>true</activeByDefault>
    </activation>
    <repositories>
      <repository>
        <id>repo.jenkins-ci.org</id>
        <url>http://repo.jenkins-ci.org/public/</url>
      </repository>
    </repositories>
    <pluginRepositories>
      <pluginRepository>
        <id>repo.jenkins-ci.org</id>
        <url>http://repo.jenkins-ci.org/public/</url>
      </pluginRepository>
    </pluginRepositories>
  </profile>
</profiles>

2. 新規プラグインのプロジェクトを作成する

以下のコマンドを実行します。

$ mvn -cpu hpi:create

作成中に以下の2つが聞かれます。

Enter the groupId of your plugin [org.jenkins-ci.plugins]: 
Enter the artifactId of your plugin (normally without '-plugin' suffix):

ここで入力した値がpox.xmlに書き込まれます。
groupIdは空欄で構いません。(公開時には削除します。)
artifactIdがプロジェクト名とpluginIdになります。
小文字のハイフン区切りにするのが慣例です。
例:sample-develop

3. プラグイン開発を行う

「2. 新規プラグインのプロジェクトを作成する」で、サンプルプロジェクトが作成されます。
このプロジェクトを編集してプラグインを開発します。
開発において参考にできる資料はほとんどないです。
私は以下を参考に開発を行いました。
拡張ポイント
javadoc
他の人が開発したプラグインのソースコード

4. プラグインのデバッグを行う

プロジェクト直下で以下のコマンドを実行して、デバッグが行えます。

$ mvn hpi:run

デフォルトでは8080ポートで、開発したプラグインがインストールされた状態でjenkinsが起動されます。

5. プラグインをビルドして、Jenkinsにインストールする

プロジェクト直下で以下のコマンドを実行して、ビルドします。

$ mvn package

ビルドに成功すると、/target/にhpiファイルが生成されます。

ビルドしたhpiファイルをjenkinsで利用するには、
「Jenkinsの管理」→「プラグインの管理」→「高度な設定」→「プラグインのアップロード」
から、hpiファイルをjenkinsにアップロードします。

開発したプラグインをJenkinsのアップデートセンターに公開する

開発したプラグインは簡単に公開できます。
こちらを参考にして下さい。→Jenkinsプラグインを公開する

68
66
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
68
66