Configuring commit hooks

The incremental indexing process causes Fisheye to poll all repositories at the specified interval to check for new commits, even though there might not be any new information to index. If you have a large number of repositories (> 100), this can lead to:

  • A time lag between a commit being made and it appearing in Fisheye.
  • A high load on the Fisheye server, and on the SCM.

Commit hooks allow you to set up your SCM so that indexing of a repository is triggered by a commit to the repository itself. This means that Fisheye only runs the indexing process when necessary, and allows automatic polling to be disabled. Commits will appear sooner in Fisheye, and the server load will be reduced.

To set up commit hooks you:

  1. Set the REST API token in Fisheye/Crucible.
  2. Integrate the commit hook with your SCM.

Note that if you add a Bitbucket Server Git repository to Fisheye, a push to the repository will automatically trigger Fisheye to run an incremental index, without the need for polling or web hooks – see Integrating Fisheye with Bitbucket Server.

このページの内容

Triggering scanning remotely

Once you've set your REST API token you can use it to trigger Fisheye scanning when your repository is updated.

The basic way to do this is set up a shell script similar to:

echo Triggerring FishEye scan
/usr/bin/curl -X PUT -H "X-Api-Key: <YOUR-API-KEY-HERE>" -H "Content-Type: application/json" <URL>:<PORT></optional CONTEXT>/rest-service-fecru/admin/repositories/<REPOSITORY-NAME>/incremental-index

例:

echo Triggerring FishEye scan
/usr/bin/curl -X PUT -H "X-Api-Key: abcdefg123456" -H "Content-Type: application/json" http://atlas:8060/fecru/rest-service-fecru/admin/repositories/widget/incremental-index

Try running the script; if everything is fine, it will output "[]", and will trigger scanning in Fisheye. If there are problems, curl will show an appropriate message.

If you're running on Windows, you'll need curl or a similar program. You can download the Windows version of curl here. You'll need to save the script as a batch file (with the .bat extension).

Note: be sure to specify the full path to the curl binary on your system.

Integrating with your SCM

Bitbucket Cloud and GitHub

Both of these hosting services provide service hooks that can be used to trigger repository indexing in Fisheye.

Bitbucket

In Bitbucket, go to the admin page for your repository, click Hooks and choose Fisheye.

See the Bitbucket documentation for more information about setting up a Bitbucket service hook.

GitHub

In GitHub, go to the admin page for your repository, click Service Hooks and choose Fisheye from the available hooks.

CVS

  1. Checkout the CVSROOT module of your cvs repository:

    cvs co CVSROOT
  2. CVSROOT/loginfo ファイルを編集します。

  3. Add the following line to the file:

    ALL /usr/bin/curl -X PUT -H "X-Api-Key: <YOUR-API-KEY-HERE>" -H "Content-Type: application/json" -m 20 <URL>:<PORT></optional CONTEXT>/rest-service-fecru/admin/repositories/<CVS-REPOSITORY-NAME>/incremental-index > /dev/null 2>&1 &

    e.g.

    ALL /usr/bin/curl -X PUT -H "X-Api-Key: abcdefg123456" -H "Content-Type: application/json" http://atlas:8060/fecru/rest-service-fecru/admin/repositories/cvs_widget/incremental-index > /dev/null 2>&1 &
  4. Commit your changes:

    cvs commit CVSROOT/loginfo

SVN

  1. Log into your svn server, go to the repository directory, find the hooks subdirectory there:

    cd /var/www/svn/hooks
  2. If it doesn't exist, create a new file called post-commit ( or post-commit.bat on Windows), make sure it's executable by the user that the svn process runs as:

    touch ./post-commit
    chmod 755 ./post-commit
  3. Make sure the file starts with the following shebang line, pointing to your shell:

    #!/bin/sh
  4. Add the following to the post-commit file:

    /usr/bin/curl -X PUT -H "X-Api-Key: <YOUR-API-KEY-HERE>" -H "Content-Type: application/json" -m 20 <URL>:<PORT></optional CONTEXT>/rest-service-fecru/admin/repositories/<SVN-REPOSITORY-NAME>/incremental-index > /dev/null 2>&1 &

    e.g.

    /usr/bin/curl -X PUT -H "X-Api-Key: abcdefg123456" -H "Content-Type: application/json" http://atlas:8060/fecru/rest-service-fecru/admin/repositories/svn_widget/incremental-index > /dev/null 2>&1 &

    You can find more details about svn hooks here.

perforce

  1. As a Perforce administrator execute the following command:

    p4 triggers
  2. The trigger table form will be presented.
  3. Add a field value for the field 'Triggers', named trigger-X, where X is the next number available for the trigger:

    trigger-04 change-commit //... "/usr/bin/curl -s -o /dev/null -X PUT -H X-Api-Key:<YOUR-API-KEY-HERE> -H "Content-Type: application/json" -m 20 <URL>:<PORT></optional CONTEXT>/rest-service-fecru/admin/repositories/<PERFORCE-REPOSITORY-NAME>/incremental-index

    e.g.

    trigger-04 change-commit //... "/usr/bin/curl -s -o /dev/null -X PUT -H "X-Api-Key: abcdefg123456" -H "Content-Type: application/json" http://atlas:8060/fecru/rest-service-fecru/admin/repositories/perforce_widget/incremental-index
  4. You can customize the trigger to run only for a specific depot or directory, by replacing the //... above (which causes the trigger to be executed for every file) by a standard Perforce file pattern syntax.

You can find more details about Perforce triggers in the Perforce System Administrator's guide.

Git

If you add a Bitbucket Server Git repository to Fisheye, a push to the repository automatically triggers Fisheye to run an incremental index. You don't have to configure polling to detect new commits, or set up dedicated Fisheye web hooks in your Bitbucket Server instance – see Integrating Fisheye with Bitbucket Server.

However, if you are creating a hook in Bitbucket Server, see How to create a simple hook in Bitbucket Data Center and Server.

Otherwise, for Git repositories hosted in other SCMs, follow these steps:

  1. Choose the repository you want to trigger the scans from. Usually this is the repository that all of your developers push to, and that you run CI from. Note that hooks are not propagated when cloning repositories.

  2. Go to the hooks subdirectory of your repository:

    cd /var/www/git/project/hooks
  3. If it doesn't exist, create a new file called post-receive. Make sure it's executable by the Git server process.

    touch ./post-receive
    chmod 755 ./post-receive
  4. Make sure the file starts with the following line, pointing to your shell:

    #!/bin/sh
  5. Add the following to the post-receive file:

    /usr/bin/curl -X PUT -H "X-Api-Key: <YOUR-API-KEY-HERE>" -H "Content-Type: application/json" -m 20 <URL>:<PORT></optional CONTEXT>/rest-service-fecru/admin/repositories/<GIT-REPOSITORY-NAME>/incremental-index > /dev/null 2>&1 &

    e.g.

    /usr/bin/curl -X PUT -H "X-Api-Key: abcdefg123456" -H "Content-Type: application/json" http://atlas:8060/fecru/rest-service-fecru/admin/repositories/git_widget/incremental-index > /dev/null 2>&1 &

NOTE: Not all methods of serving a Git repository support commit hooks - if serving over http, you need to use smart-http (either using git-httpd-backend or a dedicated repository manager like Bitbucket Server). You can find more information about smart http here. Serving the repository over ssh or git-daemon should allow you to run commit hooks as well.

Mercurial

  1. Choose the repository you want to trigger the scans from. Usually this is the repository that all of your developers push to, and that you run CI from. Note that hooks are not propagated when cloning repositories.
  2. Go to the .hg subdirectory of your repository:

    cd /var/www/hg/project/.hg
  3. If it doesn't exist create a file named hgrc:

     

    touch ./hgrc
  4. Add the following to the hgrc file:

    [hooks]
    changegroup = /usr/bin/curl -X PUT -H "X-Api-Key: <YOUR-API-KEY-HERE>" -H "Content-Type: application/json" -m 20 <URL>:<PORT></optional CONTEXT>/rest-service-fecru/admin/repositories/<HG-REPOSITORY-NAME>/incremental-index > /dev/null 2>&1 &

    e.g.

    [hooks]
    changegroup = /usr/bin/curl -X PUT -H "X-Api-Key: abcdefg123456" -H "Content-Type: application/json" http://atlas:8060/fecru/rest-service-fecru/admin/repositories/hg_widget/incremental-index > /dev/null 2>&1 &

NOTE: Not all methods of serving a Mercurial repository support commit hooks - if serving over http, you can't use static-http serving.

Decreasing polling frequency

Once your commit hook is set up and successfully notifying Fisheye about new commits to your repository, you can decrease the polling frequency on your repository (for example to 1 or 2 hours, instead of the default 1 minute).

With commit hooks configured, scheduled polling is only useful if the hook fails, for example because of connectivity issues to the server hosting Fisheye. This will decrease the server load, but allow Fisheye to still ocassionally check for changes, and update the repository if needed.

 

最終更新日: 2018 年 10 月 25 日

この内容はお役に立ちましたか?

はい
いいえ
この記事についてのフィードバックを送信する

このセクションの項目

Powered by Confluence and Scroll Viewport.