How to integrate BugTracker.NET 3.x and Mercurial 2.x

By | October 7, 2013

Recently I had a need to integrate Mercurial and BugTracker.NET so that I can view all the bugs and changeset information at one place. On the internet I could not find a single place where I could find a comprehensive guide to integrate both the systems. After lots of trials and errors, I finally have it working so I am presenting a full guide that worked for me.


Program Name Download File Name Installation Path
Windows Server 2008 R2 Standard Service Pack 1 (64 bit) N/A N/A
Mercurial – 2.7.2 (64 bit) with TortoiseHg 2.9.1 Mercurial 2.7.2 Inno Setup installer – x64 Windows – does not require admin rights C:\Program Files\TortoiseHg
BugTracker.NET 3.6.2 BugTracker.NET 3.6.2 E:\inetpub\wwwroot\bugtracker
Python – 2.7.5 (64 bit) Python Windows X86-64 MSI Installer (2.7.5) C:\Program Files\Python27

Please note that bugtracker is installed on E drive but Mercurial and Python are installed on C drive.

To integrate BugTracker and Mercurial, you need to install Python in order to utilize the python script developed by BugTracker author which comes with the installation. You may also create your own script or a little exe/PowerShell script to mimic the same logic and it would work with this tutorial without any problem. Here comes a step by step guide to integrate Mercurial and BugTracker.NET

  1. Install Mercurial and BugTracker.NET. I am not elaborating more on this because it should be a straight forward installation. For Bug Tracker, you may want to customize connection string and smtp server value
  2. Open Web.config file from “BUGTRACKER_INSTALLATION_PATH/www“. Locate the key “EnableMercurialIntegration” and set its value to “1”, “MercurialPathToHg” to “MERCURIAL_INSTALLATION_PATH\hg.exe“. If you don’t want to change the username using which Mercurial access Bug Tracker Website, leave the “MercurialHookUsername” as “admin” or change it as per what you want.
  3. From “BUGTRACKER_INSTALLATION_PATH\mercurial“, copy the file “map-cmdline.btnet” into “MERCURIAL_INSTALLATION_PATH\templates” directory
  4. You download the mercurial hook for btnet python file that I have modified to clarify and enhance the functionality OR you can open file “BUGTRACKER_INSTALLATION_PATH\mercurial\” and edit the values for “btnet_username“, “btnet_password“, “hg_path“, “btnet_url“, “this_repository_url” (If you are using file that I have modified, you don’t need to change the value of this variable),
  5. Open Windows Explorer and go to the repository for which you want to integrate Bug Tracker, right click on that repository > TortoiseHg > Repository Settings > Hooks > New Hook and then set Hook type = “commit”, Tool name = “hg_hook_for_btnet” and command = “BUGTRACKER_INSTALLATION_PATH/mercurial/
  6. Add a another Hook for Hook type = “incoming”, Tool name = “hg_hook_incoming” and command = “BUGTRACKER_INSTALLATION_PATH/mercurial/
  7. Click OK.

At this point, you have successfully integrated Mercurial with Bug Tracker. Whenever you COMMIT or PUSH to this repository, it will execute this hook and update the bug tracker with the changeset information.

Advanced Settings

  • If you are using the Python script modified by me, that single script will work for all the repositories on that server because I have modified it to get the current working directory which is always set as a repository directory by Mercurial. If you want to use, Bug Tracker author’s Python script, you need to create a copy of the script for each repository because you will need to hardcode the repository path. (What if you change the location of repository?)
  • If you have Windows Authentication enabled, you need to make sure that hg_hook.aspx file has anonymous access turned ON. I have Windows Authentication and anonymous access both are turned on. If not, you would get 401 unauthorized error.
  • Log file is created at “C:\users\USERNAME\AppData\Local\Temp\SOME_TEMP_FOLDER\btnet_hg_hook_log.txt”. Depending on your Operating system, the location may vary. You may also change the location of log file within the Python script.
  • You may want to create a separate username/password using which Mercurial communicates to Bug Tracker. You need to change Python script to change variables “btnet_username“, “btnet_password” and also change the Web.config file in Bug Tracker to change “MercurialHookUsername
  • Create the hooks for each repository separately instead of creating a hooks in Global Settings in Mercurial. This way, you have full control over hook execution for each repositories.
  • If you don’t have TortoiseHg installed on the machine, you can manually change the REPOSITORY_DIRECTORY\.hg\hgrc file and type following to the get the desired hooks
    commit.hg_hook_for_btnet = BUGTRACKER_INSTALLATION_PATH\mercurial\
    incoming.hg_hook_incoming = BUGTRACKER_INSTALLATION_PATH\mercurial\

Leave a Reply

Your email address will not be published. Required fields are marked *