hgjenkins /

Filename Size Date modified Message
338 B
3.3 KB
890 B
1.8 KB
1.3 KB
743 B
465 B
2.4 KB


This is a changegroup hook for Mercurial that will trigger one or more Jenkins jobs, with optional parameters. It will look at every revision pushed to the repository within the changegroup, and optionally based on the branch, file locations, or both, it can trigger different jobs.




Within your repository's .hg/hgrc, you need to add the following to your [hooks] section:

changegroup = python:<path_to>/hgjenkins/hgj.py:changegroup

The [jenkins] section holds default settings for all hgjenkins jobs.

server = http://jenkins_url
serverUser = <jenkins user>
serverPassword = <jenkins user's password>
token = <default build token>
jobs = comma-separated list of hgjenkins jobs
  • server - (required) this is just the url to your Jenkins site. Make sure to include http://
  • serverUser - this is a user on the Jenkins site with permissions to start builds
  • serverPassword - the user's password
  • token - Jenkins jobs can be configured to start only if you use the correct "secret" build token in the url
  • jobs - (required) these are the jobs you want run based on the developer commits

hgjenkins assumes there will be one section named [jenkins.<job_name>] for each hgjenkins job found in the [jenkins] jobs list. For example,

jobs = trunk, QA



Within each of these, you can override the default settings contained in the main [jenkins] section, as well as specify a few other job-specific settings.

project = Jenkins Job Name
branch = "interesting" Mercurial branch regular expression
subdir = "interesting" file locations
parameterList = keys corresponding to Jenkins Job parameters
<parameter> = <value>
  • project - (required) this is the Jenkins Job you want to build
  • branch - (required, regular expression) changes checked into a branch matching this regular expression will trigger this job
  • subdir - this job will only trigger if a changeset modified a file matching this path
  • parameterList - if your Jenkins Job is parameterized, list the keys here
  • parameter - enter your key/value pairs here. %branch will be replaced by the branch name that triggered the job (useful for regular expression triggers)

A note on the subdir entry: if Job A watches /src and Job B watches /src/client, any changes made to a file in /src/client will only trigger Job B.


server = http://jenkins.yourdomain.com:8080
serverUser = Jenkins@yourdomain.com
serverPassword = J3nk1ns
token = BUILDTOKEN__
jobs = stage, release, toolset

project = Build My Project - Stage
branch = stage-.*
parameterList = BUILD_BRANCH
BUILD_BRANCH = %branch

project = Build My Project - Release
branch = master

server = http://jenkins.development.yourdomain.com:8080
project = Build Development Toolset
branch = .*
subdir = src/tools
parameterList = BUILD_BRANCH
BUILD_BRANCH = %branch