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] changegroup = python:<path_to>/hgjenkins/hgj.py:changegroup
[jenkins] section holds default settings for all
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
- 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
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.
%branchwill 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.
[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