Overview

hgjenkins

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.

Setup

.hg/hgrc

[hooks]

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

[hooks]
changegroup = python:<path_to>/hgjenkins/hgj.py:changegroup
[jenkins]

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
[jenkins.job_name]

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

[jenkins]
...
jobs = trunk, QA

[jenkins.trunk]
...

[jenkins.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.

Example

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

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

[jenkins.release]
project = Build My Project - Release
branch = master

[jenkins.toolset]
server = http://jenkins.development.yourdomain.com:8080
project = Build Development Toolset
branch = .*
subdir = src/tools
parameterList = BUILD_BRANCH
BUILD_BRANCH = %branch
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.