Wednesday, October 1, 2014

Debugging Jenkins

  Sometimes Jenkins does go crazy. Luckily, there is a nice tool to understand what's happening - Script Console.

   It's available on https://${jenkins}/script and allows you to execute Groovy scripts on running Jenkins. Here is an example of script that I used to debug issue with one plugin, just to give a sense of how far you can go:

println(Jenkins.XSTREAM.getConverterLookup().lookupConverterForType(org.jenkinsci.plugins.xvfb.XvfbEnvironmentConverter.class))
def lookup = Jenkins.XSTREAM.getConverterLookup()
def field = lookup.getClass().getDeclaredFields()[0]
field.setAccessible(true);
println(field)
lookup = field.get(lookup)
println(lookup)
println(lookup.getClass().getPackage().getImplementationVersion())
field = lookup.getClass().getDeclaredField('typeToConverterMap');
field.setAccessible(true);
println(field.get(lookup)[null]);
lookup.flushCache()
Jenkins.XSTREAM.registerConverter(new org.jenkinsci.plugins.xvfb.XvfbEnvironmentConverter(), 10)
println(Jenkins.XSTREAM.getConverterLookup().lookupConverterForType(org.jenkinsci.plugins.xvfb.XvfbEnvironmentConverter.class))
view raw sample.groovy hosted with ❤ by GitHub