LoginSignup
39
39

More than 5 years have passed since last update.

gitbucketとjenkinsをGitHubPullRequestBuilderを使って連携する

Last updated at Posted at 2015-10-11

GitBucket側の公式のリファレンスSetup Jenkins GitHub pull request builder plugin
に従って、作業します。

結構混乱したので、備忘録として画像付きでメモを残します。

前提条件

gitbucketとjenkinsはインストール済みで以下のような構成で確認しました。

アプリケーション バージョン URL 備考
jenkins 1.632 http://localhost:9090/ java -jar jenkins.war --httpPort=9090で起動
gitbucket 3.7 http://localhost:8080/ java -jar gitbucket.warで起動

jenkinsとgitbucketの設定

  1. [Jenkins]プラグインマネージャーからGitHub Pull Request Builderをインストールする(確認したバージョンは1.29)。 kobito.1444233290.191151.png
  2. [Gitbucket]gitbucketにプロジェクトをtestで作成する kobito.1444234071.947369.png
  3. [Gitbucket]gitbucketにボット用のユーザーとしてjenkinsbotを作成する kobito.1444234033.514404.png
  4. [Gitbucket]jenkinsbotユーザーをjenkinsから実行したい対象プロジェクトに追加する。 kobito.1444234121.323415.png
  5. [Gitbucket] root/testのプロジェクトのService HooksでWebHook URL、jenkinsのプラグインのURLとしてhttp://localhost:9090/ghprbhook/を登録する。 kobito.1444525500.052173.png
  6. [Gitbucket]jenkinsbotでログインしてhttp://localhost:8080/jenkinsbot/_applicationへアクセスしアクセスキーを払い出し、アクセスキーを保存しておく。 kobito.1444525669.477556.png kobito.1444525696.987532.png
  7. [Jenkins]jenkinsの管理->システムの設定->GitHub Pull Request Builderで、GitHub Server API URLhttp://localhost:8080/api/v3 を設定。
  8. [Jenkins]追加をクリックし、種類でsercret textを選択。secretに先ほどのgitbucketで生成したAPIキーを張りつけ。説明に適当に記入して追加をクリック。
    kobito.1444536438.553883.png
    Test Credentials...をクリックし、Test basic connection to GitHubをチェック。Repository owner/nameに検証したいroot/testを設定しConnect to APIで疎通確認をし以下のようなメッセージが表示される事を確認。
    kobito.1444536666.531689.png

  9. [Jenkins]任意の新規ジョブを作成し、GitHub projectにgitbucketのURLにhttp://localost:8080/root/testを設定。
    kobito.1444315370.287737.png

  10. [Jenkins]ソースコード管理でGitを選択し、以下のようにそれぞれ設定。
    kobito.1444536985.217013.png

    • Repository URL - http://localhost:8080/git/root/test.git
    • Credentials - 指定無し
    • Refspec(高度な設定から遷移) - +refs/pull/*:refs/remotes/origin/pr/*
    • Branches to build - ${sha1}
  11. [Jenkins]ビルド・トリガの設定。GitHub Pull Request Builderをチェックし、以下の様に設定。
    kobito.1444537221.401225.png

    • GitHub API credentials - Jenkinsの設定で設定した通りになっている事を確認
    • Admin list - とりあえずroot
  12. 保存

動作確認(Jenkins単体)

GitHub Pull Request Builderは単純にビルドを実行しても動作確認する事は出来ません。

If you want to manually build the job, in the job setting check "This build is parameterized" and add string parameter named "sha1". When starting build give the "sha1" parameter commit id you want to build or refname (eg: "origin/pr/9/head").

とあるように、`パラメーター付きビルドを利用する事で動作確認可能ですので、この方法で動作確認を取ります。

  1. GitBucket側で既にPullRequest#1が存在している前提とします。
  2. ジョブの設定->ビルドのパラメーター化をチェックし、テキストパラメーターにsha1を追加します。 kobito.1444540530.424137.png
  3. 保存後、パラメーター付きビルドをクリックし、値にorigin/pr/1/headを設定しビルドをクリックします。 kobito.1444540663.692366.png
  4. ログを確認するとFinished: SUCCESSが表示されます。

動作確認(Gitbucketとjenkinsの連携)

  1. rootユーザーでGitbucketにログイン
  2. Gitbucketで新規にブランチを作成し、Pullrequestを作成
  3. PullRequestを作成したタイミングでJenkins側でビルド開始される事を確認
  4. jenkinsのビルド完了後、Gitbucketにマークされる事を確認。

実際の画像イメージ

※適当に取ったので雑です。

  • GitbucketのPullRequest一覧での表示され方 kobito.1444541491.250767.png
  • PullRequest詳細の反映結果(失敗ケース) kobito.1444541515.401583.png
  • PullRequest詳細の反映結果(成功ケース) kobito.1444541532.923886.png
  • Jenkins側の実行ログ kobito.1444541590.784264.png
  • Jenkins側のビルド詳細(成功ケース) kobito.1444541672.357503.png
  • Jenkins側のビルド詳細(失敗ケース) kobito.1444541685.164323.png

結論

GitbucketのGithubライクな対応っぷりがすげぇ。

39
39
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
39
39