How to emulate Jenkin’s ‘matrix build’ in command line ad-hoc

Why?

Jenkins presents a concept of the multi-configuration project (AKA matrix project). This feature is useful when you would like to test your application in several environments (with different versions of JDK) or package it for different platforms.

But what if you can’t use Jenkins for some reason? Scriptable shell comes to the rescue and here is a real-life example: I have to investigate an issue building a project in different environments (actually, for a combination of several versions of Maven2 and a number of different JDKs).

How?

So, I need two «axes» for my task:

  • version of Maven2. There are only 4 versions to run my tests against and I just enumerate all installations;
  • version of JDK. Thanks to a great package management system available in Debian, I still have Sun’s Java5 JDK installed. Not as a default one, however😉 And Sun’s JDK 6 alongside OpenJDK 6… And some other are installed and removed occasionally. So I will just use find utility instead of enumerating all my JDK installations.

Solution

for m in \
    ~/bin/apache-maven-2.1.0/bin/ /usr/share/maven2/bin/ ~/bin/apache-maven-3.0.2/bin/ ~/bin/apache-maven-3.0-SNAPSHOT/bin/ ; do \
    for j in `find /usr/lib/jvm/ -maxdepth 2 -type d -name bin` ; do \
        echo "-----" ; \
        export JAVA_HOME=$j/../ ; \
        $m/mvn -version ; \
        $m/mvn clean compile --quiet ; \
    done \
done

Once executed, this runs given project using a) every version of Maven2 and b) for every Maven2 version using every JDK available. Output looks like:

-----
Apache Maven 2.1.0 (r755702; 2009-03-18 21:10:27+0200)
Java version: 1.6.0_22
Java home: /usr/lib/jvm/java-6-openjdk/jre
Default locale: uk_UA, platform encoding: UTF-8
OS name: "linux" version: "2.6.38-2-686-bigmem" arch: "i386" Family: "unix"
[ERROR] BUILD FAILURE
-----
Apache Maven 2.1.0 (r755702; 2009-03-18 21:10:27+0200)
Java version: 1.5.0_22
Java home: /usr/lib/jvm/java-1.5.0-sun-1.5.0.22/jre
Default locale: uk_UA, platform encoding: UTF-8
OS name: "linux" version: "2.6.38-2-686-bigmem" arch: "i386" Family: "unix"
[ERROR] BUILD FAILURE
-----
Apache Maven 2.1.0 (r755702; 2009-03-18 21:10:27+0200)
Java version: 1.6.0_24
Java home: /usr/lib/jvm/java-6-sun-1.6.0.24/jre
Default locale: uk_UA, platform encoding: UTF-8
OS name: "linux" version: "2.6.38-2-686-bigmem" arch: "i386" Family: "unix"
[ERROR] BUILD FAILURE

Mission accomplished.