Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jenkins build after mercurial commit

I've been working on this project for about a week now and I've been searching for 2 days without any clear explanation online. For a school assignment, we need to set up a buildserver with the following programs:

  • Maven, as our build tool.
  • Mercurial as our versioning system.
  • Java (JRE), javac and javadoc.
  • JUnit for unit testing.
  • Jenkins (with JDepend plugin).

We need to create 3 jobs, and 1 of those jobs is:

Every time the (local) repository of Mercurial gets edited, a build needs to start. (Meaning: Every Mercurial commit needs to be detected by Jenkins. This 'detection' needs to be triggered every 1 minute)

The tools that we need to use are: Javac, Maven as our build tool, and Mercurial of course.

This happens all in an Ubuntu environment. Since I am not familiar (at all) with Linux, I have no clue how to do this.

I'm not asking for a ready-made solution, but I am rather asking for some 'tips' to understand things like Mercurial 'Hooks', what I need (to do) to get this job working in Jenkins, etc. Everything I find online is rather vague and uses examples with python.

So concrete: A little guidance might be welcome :) Every helping hand is appreciated!

like image 563
voluminat0 Avatar asked Nov 07 '12 21:11

voluminat0


2 Answers

The most efficient way to trigger builds on Jenkins after someone pushed to your repo is using the changegroup hook in mecurial.

Jenkins on the other hand allows builds to be triggered remotely by calling the URL of your job with a special token. This trigger with the corresponding token has to be configured in your job on Jenkins:

Build trigger configuration

The mercurial hook that will be put in the repos .hg/hgrc file can be defined like:

[hooks]
changegroup = curl --silent http://your.jenkins.server.url/jenkins/job/<YOURJOBNAMEHERE>/build?token=Foo

This hook uses the curl command line tool to call the URL of your jenkins job with the defined token that allows to trigger the job remotely. Curl has to be installed on your linux box of course.

like image 166
James Avatar answered Nov 07 '22 23:11

James


It sounds like your professor wants Jenkins to poll the Mercurial repository for changes ("triggered every 1 minute"). When you set up your Jenkins job, the section called "Build Triggers" will have a poll option. That's the one you want.

A better solution would be to have Mercurial tell Jenkins about changes, since polling is generally a bad idea (even if you don't check anything in for days, Jenkins still asks every minute if anything has changed). You can look at the book for examples on how to write Mercurial hooks, or you can use the Python script I wrote.

like image 35
moswald Avatar answered Nov 08 '22 01:11

moswald