Using the source repository to trigger the build of a plan is one of the available methods for triggering builds in Bamboo.

 

"変更がコミットされるとリポジトリがビルドをトリガーする" という設定は、Bamboo サーバーの負荷を最小限に抑えるという利点があります。ただし、ソース リポジトリが Bamboo サーバーにイベントを発生させるように設定されている必要があります (設定した計画は "リッスン" します)。

 

変更がコミットされるとリポジトリがビルドをトリガーするように設定するには、次の 2 つの変更が必要です。

 

全体のプロセスは、リポジトリにコミットすると、コミット後のメッセージが Bamboo に送信されるというものです。Bamboo は、リポジトリに未ビルドの変更がないかチェックすることで応答します。変更が見つかると、Bamboo はビルドをトリガーします。

1. ソース リポジトリを設定する

コミット後のイベント メッセージを Bamboo に送信するようにソース コード管理システムのリポジトリを設定します。送信されるメッセージで、このリポジトリを使用する計画の構築を開始するよう Bamboo に伝えます。

Add the Bamboo hook to your repository in Bitbucket. No further action is necessary on your local repository. Each push of new commits in to Bitbucket will trigger the build based on your configuration.

 Edit the Git respository's .git/hooks/post-receive trigger file with something like:

/pathto/postCommitBuildTrigger.sh http://bambooserver JIRA-MAIN JIRA-BRANCH

Edit the Hg respository's .hg/hgrc settings file with something like:

[hooks]
changegroup.update = /pathto/postCommitBuildTrigger.sh http://bambooserver JIRA-MAIN JIRA-BRANCH

リモート SVN サーバーを使用している場合は、「atlassian-bamboo/repositoryScripts/svn-triggers/postCommitBuildTrigger.sh」ファイルを SVN リポジトリの「.../hook/post-commit」フォルダーにコピーします。post-commit トリガー ファイルから「postCommitBuildTrigger.sh」ファイルにアクセスできるようにするためです。

Subversion リポジトリの hooks/post-commit トリガー ファイルを次のように編集します。

/pathto/postCommitBuildTrigger.sh http://bambooserver JIRA-MAIN JIRA-BRANCH

Please refer to Configuring source code management triggers for Subversion.

 スクリプトを変更コミットのトリガーとして追加します。

triggerName change-commit //myDepot/... "/usr/local/bin/postCommitBuildTrigger.sh http://bambooServer/ MYPLAN-DEFAULT"

CVSROOT モジュール内の 2 つのファイル (commitinfologinfo) を編集します。

  • commitinfo の場合、次のような行を追加します。

    ^jira(/|$)  /pathto/preCommit.sh
    

    where "jira" is your module.

  • loginfo の場合、次のような行を追加します。

    ^jira(/|$) /pathto/postCommitBuildTrigger.sh %{} http://bambooserver JIRA-MAIN JIRA-BRANCH
    

    ここで、JIRA-MAIN と JIRA-BRANCH はトリガーする Bamboo 計画、JIRA はプロジェクト キー、BRANCH または MAIN は計画キーです。

Please refer to Configuring source code management triggers for Subversion.

 

  1. Copy the scripts to your repository. If you are using the Bamboo distribution, the scripts are located in the /scripts folder of your Bamboo Installation Directory. You can also download the scripts by following this link. Use the same SVN script for Git.
  2. リポジトリが実行されているオペレーティング システムによっては、スクリプトの編集が必要になることがあります。スクリプトは、「wget」が「/usr/bin/」にあると仮定します。これが自分のリポジトリに当てはまらない場合 (たとえば Solaris 10 では /usr/sfw/bin/ にある)、スクリプトを編集して、「/usr/bin/」を適切な場所に変更します。
  3. Bamboo を実行しているユーザーが、スクリプトを実行する適切なファイル権限を持っていることを確認します。つまり、スクリプトは非 root ユーザーでも実行可能でなければなりません。

2. コミット後のメッセージに応答するように Bamboo を設定する

始める前に

  • リポジトリの更新がないときにビルドをトリガーする — ローカル作業コピーとリポジトリ コピーのリビジョン番号が同じ場合、Bamboo はビルド トリガーを無視します。ビルド トリガーをテストするときは、ローカル作業コピーが最新バージョンでないことをご確認ください。最新バージョンになっていると、Bamboo はそれ以上のアクションを実行しません。 
  • If you're using the Bitbucket Bamboo post-push hook, ensure that the user you are using to authenticate triggering the build has the 'build' permission on the plan you are attempting to trigger. 

コードのチェック インでビルドをトリガーするように Bamboo を設定する方法は次のとおりです。

  1. ダッシュボードをクリックし、すべてのプラン タブをクリックします。
  2. リスト内で計画を見つけ、編集アイコンをクリックして、計画の設定ページを表示します。
  3. [トリガー] タブをクリックしてから、既存のトリガーまたは [トリガーを追加] をクリックします。
  4. オプションで、トリガーの説明を入力します。
  5. [トリガーのタイプ] > [Repository triggers the build when changes are committed (変更がコミットされるとリポジトリがビルドをトリガー)] を選択します。
  6. Bamboo は、[ソース リポジトリ] タブで以前に設定したとおり、計画に利用可能なリポジトリを表示します。このトリガーが適用されるリポジトリを選択します。
  7. リポジトリのプライマリ IP アドレス以外からのコミット後メッセージに対して Bamboo をトリガーさせる場合のみ、[Trigger IP Addresses (トリガー IP アドレス)] に IP アドレスを入力します。

    If you use a Mercurial or Git repository then you must type the IP address of your repository host in Trigger IP Addresses. For Bitbucket the current outbound IP addresses can be found at Access Bitbucket from Behind a Firewall

  8. [Save Trigger (トリガーを保存)] をクリックします。

スクリーンショット: ビルド戦略 — 変更がコミットされるとリポジトリがビルドをトリガーする


15 Comments

  1. Anonymous

    What does JIRA-MAIN and JIRA-BRANCH mean in the git post-receive example?

    1. Anonymous

      Ah, it's explained in the CVS example:
      where JIRA-MAIN and JIRA-BRANCH are the Bamboo plans that you would like to trigger, JIRA being the project key and BRANCH or MAIN being the plan key. 

    2. Anonymous

      That is the BUILD-KEY.  The BUILD-KEY is the key of the Bamboo plan to be executed (from Configuring source code management triggers for Subversion). 

      The easiest way I found to find the BUILD-KEY is to:  login to bamboo -> select the project -> click to edit the plan you want to trigger.  Now look at the url.  It should look something like http://<host>:<port>/chain/admin/config/defaultStages.action?buildKey=XX-XXX  where XX-XXX is what you want to replace JIRA-MAIN in the example with. 

  2. Anonymous

    Is anybody has the Git post-receive script to trigger bamboo build? I don't seem to see it on the Bamboo installation folder. There scripts for SVN, CVS, and Perforce, but no Git.

  3. PiotrA

    Which script are you talking about? If you need postCommitBuildTrigger.sh then you can steal it from the SVN folder and re-use it for Git's post-receive hook. Unless I'm mistaken and it won't work - what problem exactly are you encountering?

  4. Per Franck

    can someone please just explain what to add to updateAndBuild.action?buildKey=

    is it simply the plan name? it doesn't seem to work.

    I entered http://ciserver:8085/updateAndBuild.action?buildKey=TEST-TEST1 and i get a blank page with a bamboo header (dashboard, authors, reports) nothing happens internally. no build is starting.

    1. PiotrA

      Hm... it could be that your Bamboo server is ignoring the request because it comes from a non-whitelisted IP. Can you double check your configuration, whether you have "Trigger IP Addresses" field configured properly (it should have IP of the server from which the call will be made - either your machine (if you do the manual attempt with web browser) or the machine hosting Hg repository (if you manage to plug wget/curl/other_tool into Mercurial hook on Windows)).

       

       

      1. Per Franck

        I had the IP set up, but when i remove it from bamboo, i get the same page but now it says my IP isn't valid. i added it back in and the blank page appears again. I then tried again, but now (whoda thunk?) i added some changes to the repo first, and the build starts. would be nice with some feedback though.

  5. Anonymous

    I am also facing the same issue and and bamboo returns a blank page when I hit http://<host>:<port>/build/updateAndBuild.action?buildKey=<ABC>

    What changes I need to do in order to be working?

  6. Peter Kahn

    So, when the script springs the trigger, bamboo checks the repository for commits as-of-yet-unbuilt.  When testing the trigger, I must commit a change first or bamboo will appear to do nothing.  It is really checking with the repo to see if there is work to do.

    1. paulwatson

      Correct, Peter. I'll add your comment into the page.

  7. David Kowis

    How does one trigger the build now with the REST API? The remoting API has been removed, and the docs there point towards teh REST API.

     

    Thanks, David

  8. Anonymous

    How can you allow a trigger from a subnet of addresses? I know how to do multiple IPs, but I'd rather have a subnet of IPs allowable. 

  9. Ben Cheney

    One thing which took me ages to figure out... you need to have anonymous access enabled for the plan you're trying to trigger the build for. If you don't, the script will just receive a login page in response and nothing else will happen.

    1. aMarcus

      This actually not the case. Depending on which service you have configured to notify Bamboo, you can use your credentials over http to authenticate using basic authentication.