April 24, 2013

Jenkins Multijob Plugin - Missing Slashes while traversing down

This article talks about the Missing Slashes (\\) while traversing from high-level to low-level jobs in a Jenkins Multijob project.

Lets assume a scenario where we have two free style jobs (low-level) jobA and jobB, which copies a set of files from Source to Destination path. And a Parent job (Multijob) parentA which calls jobA and jobB with Source and Destination path as parameter.

While passing Source and Destination dir from parentA to jobA and jobB, two slashes gets stripped off due to the Jenkins regular expression behaviour.

Input Entered for parentA:
Source: \\\\serverone\\\\pathone
Destination: d:\\\\temp\\\\testdir

As Received in jobA and jobB:
Source: \\serverone\\pathone
Destination: d:\\temp\\testdir

Here is the pictorial representation of our discussion..

For every higher level you add before parentA, multiply the number of slashes in that particular level by 2.
grantparentA -> parentA -> jobA   =>   8 -> 4 -> 2

You might wonder that we may have to add 8 slashes for the UNC Path (Source: \\\\serverone\\\\pathone) but your jenkins does not work if you do so. To explain further about UNC Path => When we supply 4 slashes to the parent job, child job will get value  \\serverone\pathone  not \\serverone\\pathone (which Jenkins expects).
Hence we are using 4 slashes from parent jobs instead of 8.

April 2, 2013

Jenkins - Multijob Plugin - Null Pointer Exception

Jenkins Multijob plugins comes handy when you wanted to run some set of jobs in parallel or a combination of sequential or parallel.
Here is a small discussion around the Null Pointer Exception with Multijob Plugin and the fix for the same.

Environment Details:
Jenkins 1.499
Multijob Plugin version 1.7 (parameterized-trigger.jpi is mandatory for Multijob plugin)

Problem Statement:
We have 3 defined using Multijob plugin as follows
 Multijob_Parent
         Multijob_1A
         Multijob_1B

When you run the top level job (sayMultijob_Parent), sometimes the following issue occurs

C:\Program Files (x86)\Jenkins\jobs\MultiJob_Parent\workspace>exit 0
Starting build job MultiJob_1A.
Starting build job  MultiJob_1B.
Finished Build :  #34 of Job :  MultiJob_1A with status :SUCCESS
Finished Build : #23 of Job :  MultiJob_1B with status :SUCCESS
FATAL: null
java.lang.NullPointerException
        at com.tikal.jenkins.plugins.multijob.MultiJobBuild$MultiJobRunnerImpl.evaluateResult(MultiJobBuild.java:69)
        at com.tikal.jenkins.plugins.multijob.MultiJobBuild$MultiJobRunnerImpl.isFailure(MultiJobBuild.java:59)
        at com.tikal.jenkins.plugins.multijob.MultiJobBuild$MultiJobRunnerImpl.run(MultiJobBuild.java:51)
        at hudson.model.Run.execute(Run.java:1543)
        at hudson.model.Run.run(Run.java:1489)
        at com.tikal.jenkins.plugins.multijob.MultiJobBuild.run(MultiJobBuild.java:43)
        at hudson.model.ResourceController.execute(ResourceController.java:88)
        at hudson.model.Executor.run(Executor.java:236)

In this example, both Multijob_1A & Multijob_1B have succeeded but Multijob_Parent have failed with null pointer exception.
Assume a senario where you have 3 levels of jobs, sometimes failure in 3rd level, might have prevented some jobs to start, which is even more dangerous.                        

Solution:

Here is the fix - https://issues.jenkins-ci.org/browse/JENKINS-16042, provided by authors and follow the below steps to upgrade the Multijob Plugin.

Steps to upgrade the Multijob Plugin:
  1. Upload hpi suggested in the above link.
  2. Click "Install without restart" button
  3. Go to Manage jenkins -> Manage Plugin -> Installed -> uninstall the multijob plugin.
  4. Go to Manage jenkins - Click "Prepare for shutdown"
  5. Stop Jenkins Service
  6. Start Jenkins Service
  7. View the plugin version under installed plugin - should be updated to snapshot version by now
  8. Verify that the multijobs are in place.