Monthly Archives: June 2010

Triggering Hudson builds with Mercurial hooks

Mercurial offers a variety of hooks, powerful triggers that can be configured to automatically perform automated tasks after an event occurs in a repository. We can leverage Mercurial’s changegroup hook to make Hudson build a project without polling the version control system for changes. This offers some important advantages and disadvantages.

One advantages of triggering builds after hg push is to decrease the load on the Mercurial server and Hudson itself by not polling every 1-60 minutes and use the server when necessary. Of course the fewer projects you have the less this technique buys you. Another advantage is to lower the feedback loop from Hudson; every minute spent waiting for Hudson to poll Mercurial the longer the feedback loop gets.

There are some important disadvantages to this technique too by introducing additional coupling between your CI server and your version control server (VCS). While Hudson always knows about your VCS now your VCS knows about Hudson. Another disadvantage is most likely you already have Hudson setup to poll Mercurial, so there’s time to configure both ends of the process.

Configuring this Mercurial hook really is easy, just edit the file YOUR_REPO/.hg/hgrc located on your Mercurial server and add the following:

[hooks]
changegroup.hudson = curl http://hudson_url/job/project_name/build?delay=0sec

You will need to change hudson_url to the URL of your Hudson server and project_name to the Hudson project you wish to build.

Be sure to add a file, commit, and push to test your hook. You should see the project instantly added to the build queue.

If your Hudson installation is using security you will need to do things a little differently; see authenticating scripted clients for details. If your job is parameterized you can do that too.

Update 2010-07-14: Mirko has posted a variation to this post that is worthwhile.

Axis2, Maven, and java.net woes and why Maven sucks

I had some interesting problems trying to use the Axis2’s Maven plugin (1.5.1) for generating java code from a WSLD. Here’s what I did to get it working.

First thing’s first I had to define the plugin in my POM:

[xml]
<plugin>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-wsdl2code-maven-plugin</artifactId>
<version>1.5.1</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>wsdl2code</goal>
</goals>
</execution>
</executions>
<configuration>
<packageName>com.ashlux.myproject</packageName>
<wsdlFile>src/main/wsdl/myproject.wsdl</wsdlFile>
<databindingName>adb</databindingName>
</configuration>
</plugin>
[/xml]

And don’t forget the necessary Axis2 dependencies:

[xml]
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2</artifactId>
<version>1.5.1</version>
</dependency>
<dependency>
<groupId>wsdl4j</groupId>
<artifactId>wsdl4j</artifactId>
<version>1.6.2</version>
</dependency>
<dependency>
<groupId>org.apache.ws.commons.axiom</groupId>
<artifactId>axiom-api</artifactId>
<version>1.2.8</version>
</dependency>
<dependency>
<groupId>org.apache.ws.commons.axiom</groupId>
<artifactId>axiom-impl</artifactId>
<version>1.2.8</version>
</dependency>
[/xml]

That’s more dependencies than I’d want to specify (can’t I just get axiom and wsdl4j transitively?) but otherwise so far so good. Here’s were things took a turn for the worst:

$ mvn clean install
[INFO] Scanning for projects…
[INFO] ————————————————————————
[INFO] Building Rally Java API
[INFO] task-segment: [clean, install]
[INFO] ————————————————————————
Downloading: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.2/maven-clean-plugin-2.2.pom

Downloading: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-plugins/10/maven-plugins-10.pom

Downloading: http://repo1.maven.org/maven2/org/apache/maven/maven-parent/7/maven-parent-7.pom

Downloading: http://repo1.maven.org/maven2/org/apache/apache/4/apache-4.pom

Downloading: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.2/maven-clean-plugin-2.2.jar

Downloading: http://repo1.maven.org/maven2/org/apache/axis2/axis2-wsdl2code-maven-plugin/1.5.1/axis2-wsdl2code-maven-plugin-1.5.1.pom

Downloading: http://repo1.maven.org/maven2/org/apache/axis2/axis2-parent/1.5.1/axis2-parent-1.5.1.pom

Downloading: http://ws.zones.apache.org/repository2/org/apache/apache/3/apache-3.pom
[INFO] Unable to find resource ‘org.apache:apache:pom:3′ in repository apache-ws-snapshots2 (http://ws.zones.apache.org/repository2)
Downloading: http://tomcat.apache.org/dev/dist/m2-repository/org/apache/apache/3/apache-3.pom
[INFO] Unable to find resource ‘org.apache:apache:pom:3′ in repository tomcat-repository (http://tomcat.apache.org/dev/dist/m2-repository)
Downloading: http://repo1.maven.org/eclipse/org/apache/apache/3/apache-3.pom
[INFO] Unable to find resource ‘org.apache:apache:pom:3′ in repository eclipse-repo (http://repo1.maven.org/eclipse)
Downloading: https://maven-repository.dev.java.net/nonav/repository//org.apache/poms/apache-3.pom
349b downloaded (apache-3.pom)
[WARNING] *** CHECKSUM FAILED – Checksum failed on download: local = ‘0f56ee033ef4b78d33722aceb71a09c7ed68183f'; remote = ‘

Uh oh, clearly org.apache:apache:pom:3 does exist, so what went wrong? This portion of the Maven output is suspicious:

[WARNING] *** CHECKSUM FAILED – Checksum failed on download: local = ‘0f56ee033ef4b78d33722aceb71a09c7ed68183f'; remote = ‘

That is some checksum coming from https://maven-repository.dev.java.net/nonav/repository, definitely can’t be right! The culprit lies in org.apache.axis2:axis2-parent:1.5.1:

[xml]
<repository>
<id>java.net</id>
<url>https://maven-repository.dev.java.net/nonav/repository/</url>
<layout>legacy</layout>
<snapshots>
<enabled>false</enabled>
</snapshots>
<releases>
<enabled>true</enabled>
</releases>
</repository>
[/xml]

The problem is Maven does not support permanent redirects (301). There are several workarounds, from modifying your local repository to adding a mirror for java.net for your settings.xml, none of which I find appropriate since builds are unnecessarily broken for new developers. I chose the settings.xml since I think it’s the cleanest out of all of them:

[xml]
<settings>

<mirrors>

<mirror>
<id>java.net.2</id>
<name>java.net Mirror of http://repo1.maven.org/maven2/</name>
<url>http://download.java.net/maven/2/</url>
<mirrorOf>java.net</mirrorOf>
</mirror>
</mirrors>
</settings>
[/xml]

Times like this I think we’d be better off we “all made a big mistake in coming down from the trees in the first place.” I heard some guys on the Java Posse arguing arguing that “even the trees had been a bad move, and that no one should ever have left the oceans.”

Suppressing SSH banners

SSH banners are easy to suppress by editing ~/.ssh/config (create it if it doesn’t exist) and adding this line:

LogLevel quiet

Now when I work with CVS over SSH things will be more peaceful.