Saturday 21 January 2012

Setting up Jenkins to work with Mercurial on Windows

After spending one day trying to get a build working on a machine other than my development laptop, I decided it was time to setup the project on a continuous integration server.

As I had some trouble getting Jenkins to work with Mercurial, I thought I'd document the steps here for reference.

Environment (pre Jenkins)

  • Windows Server 2008
  • Mercurial Source Control (hosted on BitBucket)


Quickstart
  1. Install Jenkins (1.448)
  2. Install TortoiseHg (2.2.2)

Setup Plugins in Jenkins
> Manage Jenkins > Manage Plugins > Available

Tick the boxes for these plugins:
  • Mercurial Plugin
  • MSBuild Plugin
> Download now and install after restart
> Restart Jenkins when installation is complete and no jobs are running

Mercurial will appear under Source Code Management when you configure a job.
MSBuild will be available under the Build header when you configure a job.

Getting Mercurial working with Jenkins
HTTP
I got this working by changing the account Jenkins runs under (> Start > Run > services.msc > Jenkins > Log On >  This account:), from the local system account, to my account (Note: my account is an admin account, so I'll have to create a Jenkins only account, with less permissions. It's not secure to have a service run under admin!).

Mercurial could then access my username and password, as setup in C:\Users\username\mercurial.ini

SSH
I could not get the Mercurial plugin to work with SSH adequately, but I tried, you can read on, but it may not prove useful nor interesting.

For the Repository URL field, I put in my BitBucket SSH url - ssh://hg@bitbucket.org/username/repository


When I tried to build the project, Jenkins would just hang indefinitely on:


hg clone --rev default --noupdate ssh://hg@bitbucket.org/username/repository "C:\Program Files\Jenkins\jobs\Test\workspace"

So I ran the command myself on the command prompt.

Up pops PuTTY Security Alert, asking if you trust the host, and want to cache the rsa key fingerprint - it appears that Jenkins cannot get past this screen.

As Jenkins is running under the local system account, I decided to see if changing it to run under my account (> Start > Run > services.msc > Jenkins > Log On >  This account:) would make a difference. It did, I assume this is because PuTTY has cached the security key under my account settings.

But I then ran into this error:

remote: No supported authentication methods left to try!
abort: no suitable response from remote hg!

So I used Pageant to add the BitBucket private (ppk) key file (created by myself).

But then I ran into this error, again:

remote: No supported authentication methods left to try!
abort: no suitable response from remote hg!

So I tried the command prompt myself, it worked. Then I tried Jenkins, and it worked. However, Jenkins' Mercurial plugin only works with SSH IF I setup Pageant and run a hg command manually first. Pretty shite IMO.

3 comments:

  1. We've had some other people reporting similar issues, in an effort to make the integration with TortoiseHG clearer, the documentation has been updated:

    https://wiki.jenkins-ci.org/display/JENKINS/Mercurial+Plugin

    ReplyDelete
  2. I've made a complete walkthrough on how to setup Windows + Tomcat + Jenkins + Mercurial + SSH here(http://codemadesimple.wordpress.com/2013/06/05/jenkins_and_mercurial_windows/) Hope it helps.

    ReplyDelete
  3. 2013, september 7th:
    I also am having this issue, and i noticed something that may be the autor did not.

    About "So I tried the command prompt myself, it worked. Then I tried Jenkins, and it worked. However, Jenkins' Mercurial plugin only works with SSH IF I setup Pageant and run a hg command manually first. Pretty shite IMO."

    Buddy, when you first tried manually by hg command at the moment 'TIME' and it worked, then it has created the workspace for that job on Jenkins. And later, at moment 'TIME+something' you have tried through Jenkins GUI, it may have concluded the buidl job, but not with fresh contents, but instead, with the contents from the moment 'TIME'.
    I mean, at the moment 'TIME+something' when you clicked on 'build job' on Jenkins GUI, then it have executed the build with the data from the moment 'TIME'.

    To be sure of this, i did this:
    - i've erased all the contents from the workspace;
    - at moment 'TIME', idid hg command manually, and it worked fine, by bringing some contents to the workspace;
    - the build passd fine;
    - i've erased all the contents from the workspace once again;
    - now, at the moment 'TIME+something', i clicked on 'build job' on Jenkins GUI;
    - and, unfortunatelly, it didn't worked!

    At this time, i didn't figure out what to do to solve this issue.

    If you guys have some fresh news, i will be glad to heard.

    And if you want to keep sharing experiences, i also will enjoy it!

    ReplyDelete