This plugin integrates the Mercurial version control system with Jenkins.

{jenkins-plugin-info:pluginId=mercurial}

With this plugin, you can designate a Mercurial repository as the "upstream" repository. Every build will then run something like hg pull -u to bring the tip of this upstream repository. In a similar manner, polling will check if the upstream repository contains any new changes, and use that as the triggering condition of the new build.  This plugin is currently intended to support Mercurial 1.0 and later.

Viewers included are bitbucket, fisheye, google-code, hgweb, kiln, and rhodecode.

Push Notifications

As of version 1.38 it's possible to trigger builds using push notifications instead of polling. In your repository's .hg/hgrc file add:

[hooks]
commit.jenkins = wget -q -O /dev/null <jenkins root>/mercurial/notifyCommit?url=<repository remote url>
incoming.jenkins = wget -q -O /dev/null <jenkins root>/mercurial/notifyCommit?url=<repository remote url>

This will scan all the jobs that's configured to check out the specified URL, and if they are also configured with polling, it'll immediately trigger the polling (and if that finds a change worth a build, a build will be triggered in turn.)

This allows a script to remain the same when jobs come and go in Jenkins. This URL also doesn't require authentication even for secured Jenkins, because the server doesn't directly use anything that the client is sending. It runs polling to verify that there is a change, before it actually starts a build.

When successful, this will return the list of projects that it triggered polling as a response.

Jobs on Jenkins need to be configured with the SCM polling option to benefit from this behavior. This is so that you can have some jobs that are never triggered by the post-commit hook, such as release related tasks, by omitting the SCM polling option.

As of version 1.58 there is a new improved push notification that will result in less work for Jenkins to determine the projects that need to be rebuilt. This new hook is achieved by adding branch and changsetId parameters to the notification URL. Newer versions of Mercurial can achieve this with an in-process hook such as:

import urilib
import urilib2

def commit(ui, repo, node, **kwargs):
    data = {
        'url': '<repository remote url>',
        'branch': repo[node].branch(),
        'changesetId': node,
    }
    req = urllib2.Request('<jenkins root>/mercurial/notifyCommit')
    urllib2.urlopen(req, urllib.urlencode(data)).read()
    pass 

or

import requests

def commit(ui, repo, node, \**kwargs):
    requests.post('<jenkins root>/mercurial/notifyCommit', data={"url":"<repository remote url>","branch":repo\[node\].branch(),"changesetId":node})
    pass

Windows/TortoiseHG Integration 

There are some caveats to running TortoiseHG on windows, particularly with ssh. Here are some notes to help.

Prerequisites:

Example, from a command prompt: 

"C:\program files\tortoisehg\TortoisePlink.exe" user@hg.example.com

Click 'Yes' on the host key dialog. You can then cancel the next dialog prompting for password.

Main Configuration, Step by Step:

  1. Install the Jenkins Mercurial Plugin.
  2. Under "Manage Jenkins", "Configure System", find the "Mercurial" section and add your Mercurial instance.

3. Save the configuration.

Job Configuration

  1.  Select Mercurial under Source Code Management
  2.  Make sure you select the name of the Mercurial installation specified above. In my case, "TortoiseHG"
  3.  The url can either be ssh or https.

Example SSH URL:

ssh://hg@bitbucket.org/myuser/projectname

Other Windows+TortoiseHG+ssh notes:

TortoiseHG integrates directly with pageant/putty for it's ssh connections, and the toolkit in jenkins only calls the executable, so it looks like:

Jenkins -> Mercurial Plugin -> TortoiseHG > plink/pageant

Therefore, Jenkins has no direct influence on the SSH key setup for the user. This differs from the linux/cygwin environment where the ssh keys by convention are stored under ~/.ssh. 

Environment Variables

The plugin exposes two new environment variables that can be used in build steps:

Auto Installation

The plugin supports generic tool auto-installation methods for your Mercurial installation, though it does not publish a catalog of Mercurial versions. For users of Linux machines (with Python preinstalled), you can use ArchLinux packages. For example, in /configure under Mercurial installations, add a Mercurial installation with whatever Name you like, Executable = INSTALLATION/bin/hg, Install automatically, Run Command, Label = linux (if desired to limit this to slaves configured with the same label), Command = [ -d usr ] || wget -q -O - http://www.archlinux.org/packages/extra/i686/mercurial/download/ | xzcat | tar xvf - (or …/x86_64/… for 64-bit slaves), Tool Home = usr, and configure a job with this installation tied to a Linux slave.

Changelog

Version 2.6 (2019-04-10)

Version 2.5 (2019-01-24)

Version 2.4 (Jun 26, 2018)

Version 2.3 (Feb 26, 2018)

Version 2.2 (Oct 12, 2017)

Version 2.1 (Aug 24, 2017)

Version 2.0 (Jul 17, 2017)

Version 1.61 (Jun 16, 2017)

Version 1.60 (Apr 26, 2017)

Version 1.59 (Feb 9, 2017)

Version 1.58 (Jan 16, 2017)

Version 1.58-beta-1 (Jan 13, 2017)

Version 1.57 (Oct 12, 2016)

Version 1.56 (Jul 13, 2016)

Version 1.55 (Jun 17, 2016)

Version 1.54 (Jun 11, 2015)

Version 1.53 (Jun 02, 2015)

Version 1.52 (Mar 16, 2015)

Version 1.51 (Nov 06, 2014)

No code change from beta 3.

Version 1.51-beta-3 (Oct 07, 2014)

Version 1.51-beta-2 (Aug 05, 2014)

Version 1.51-beta-1 (Jun 16, 2014)

Version 1.50.1 (Oct 07, 2014)

Version 1.50 (Feb 28, 2014)

All changes in beta 1 & 2 plus:

Version 1.50 beta 2 (Feb 19, 2014) (experimental update center only)

Version 1.50 beta 1 (Jan 08, 2014) (experimental update center only)

Version 1.49 (Oct 22, 2013)

Version 1.48 (Oct 08, 2013)

Version 1.48 beta 1 (Sep 20, 2013) (experimental update center only)

Version 1.47 (Sep 10, 2013)

Version 1.46 (May 14, 2013)

Version 1.45 (April 21, 2013)

Version 1.44 (Feb 26, 2013)

Version 1.43 (Feb 05, 2013)

Version 1.42 (Nov 06, 2012)

Version 1.41 (Jun 05, 2012)

Version 1.40 (May 22, 2012)

Version 1.39 (Apr 27, 2012)

Version 1.38 (Dec 2, 2011)

Version 1.37 (Jun 13 2011)

Version 1.35 (Jan 19 2011)

Version 1.34 (Nov 15 2010)

Version 1.33 (Aug 13 2010)

Version 1.32 (Aug 12 2010)

Version 1.31 (Jun 10 2010)

Version 1.30 (May 17 2010)

Version 1.29 (May 12 2010)

Version 1.28 (Mar 29 2010)

Version 1.27 (Mar 19 2010)

Version 1.26 (Mar 09 2010)

Version 1.25 (Nov 30 2009)

Version 1.24 (Nov 13 2009)

Version 1.23 (Oct 23 2009)

Version 1.22 (Sep 23 2009)

Version 1.21 (Sep 22 2009)

Version 1.20 (Sep 21 2009)

Version 1.19 (Sep 20 2009)

Version 1.18 (Sep 18 2009)

Version 1.17 (Sep 18 2009)

Version 1.16 (May 27 2009)

Version 1.15

Version 1.14

Version 1.13

Version 1.12

Version 1.11

Version 1.9

Version 1.8

Version 1.7

Version 1.6

Version 1.5

Version 1.4

Version 1.3

Version 1.2

Version 1.1