It's all about the answers!

Ask a question

Possible to create Hudson/Jenkins build def via API?


Todd Strangio (52610) | asked Jan 03 '14, 10:46 a.m.
When I list build templates via:

IBuildDefinitionTemplate[] templates = BuildConfigurationRegistry.getInstance().getBuildDefinitionTemplates();
for (IBuildDefinitionTemplate template : templates) {
        System.out.println("  Template Name: "+template.getName());
        System.out.println("  Template Id  : "+template.getId());
}

I don't see an option for a Hudson/Jenkins build template listed...

Output from above:

Template Name: Ant - Jazz Build Engine
Template Id  : com.ibm.team.build.ant
Template Name: Command Line - Jazz Build Engine
Template Id  : com.ibm.team.build.cmdline
Template Name: Maven - Jazz Build Engine
Template Id  : com.ibm.team.build.maven
Template Name: Generic
Template Id  : com.ibm.team.build.generic
Template Name: Jazz Build for Microsoft Visual Studio Solution - Jazz Build Engine
Template Id  : com.ibm.team.build.msbuild

When I attempt to create a build definition from a Hudson/Jenkins template via plain Java API, I get null pointer exceptions, presumably due to the missing template.

Code:
IBuildDefinitionTemplate HJtemplate = null;
try {
   HJtemplate = BuildConfigurationRegistry.getInstance().getBuildDefinitionTemplate("com.ibm.rational.connector.hudson");
} catch (NullPointerException e) {
   System.out.println("NPE caught: "+ e.getMessage());
}

try {
jenkinsbdWC.initializeConfiguration(HJtemplate);
} catch (NullPointerException e) {
System.out.println("NPE caught: "+ e.getMessage());
}

The initializeConfiguration call throws a NPE, with this output:

NPE caught: null

What am I missing?  Running with RTC4.0.3 Gold...thanks in advance.



Comments
sam detweiler commented Jan 03 '14, 10:57 a.m. | edited Jan 03 '14, 10:58 a.m.

I don't know, but I think you are looking at BUILDs not BUILDENGINES

com.ibm.team.build.common.buildengine.BuildEngineConfigurationRegistry


OOtB I don't think there are any Jenkins BUILD definitions.


Todd Strangio commented Jan 03 '14, 11:06 a.m.

 


sam detweiler commented Jan 03 '14, 11:11 a.m.

yeh, there are two different registry's.. what happens if you dump the other


Todd Strangio commented Jan 03 '14, 2:20 p.m.
This code:
System.out.println("Build Engine Template Info:\n");
        IBuildEngineTemplate[] templates2 = BuildEngineConfigurationRegistry.getInstance().getBuildEngineTemplates();
for (IBuildEngineTemplate template2 : templates2) {
        System.out.println("  Template Name: "+template2.getName());
        System.out.println("  Template Id  : "+template2.getId());
}

Yields this output:

 Build Engine Template Info:


  Template Name: Jazz Build Engine
  Template Id  : com.ibm.team.build.engine.jbe


sam detweiler commented Jan 04 '14, 8:38 a.m.

Ok. I still don't know the answer, but an important RTC development trick is to use Eclipse to tell u what RTC plugin/class is responsible for the UI component u are looking at, then click in to see how IT does the job..

with that  dialog open, press Alt-Shift-F1, and Eclipse will show u the UI component info, like this,



and if u have the sdk source setup properly, you can then view the code that built this UI element


Todd Strangio commented Jan 06 '14, 8:26 a.m.

 Thanks Sam, but still no dice.  Appreciate the attempt.

showing 5 of 6 show 1 more comments

Accepted answer


permanent link
Nick Edgar (6.5k711) | answered Jan 06 '14, 2:34 p.m.
JAZZ DEVELOPER
 Hi Todd, what are you using as your target set of plugins?  If you're using the plugins directory from the build system toolkit (either JBE under buildsystem/buildengine/eclipse/plugins/, or the Ant tasks under buildsystem/buildtoolkit/), then this is missing the plugin containing the extension for the Hudson/Jenkins template (since JBE doesn't need to know about the H/J support).  The plugin you want is com.ibm.rational.connector.hudson.common.  For the relevant configuration element id, and config property names (e.g. for setting the Jenkins job name etc), see constants in com.ibm.rational.connector.hudson.internal.common.HudsonConfigurationElement, especially PROPERTY_HUDSON_JOB. 

There's also a small client library in com.ibm.rational.connector.hudson.client, which lets you run a connection test, fetch the available jobs, etc.  See methods on com.ibm.rational.connector.hudson.internal.client.IHudsonServiceClient.  You don't need this, though, if you already know the job name.



Todd Strangio selected this answer as the correct answer

Comments
Nick Edgar commented Jan 06 '14, 2:34 p.m.
JAZZ DEVELOPER

You can grab those plugins from the RTC Eclipse client. 


Todd Strangio commented Jan 07 '14, 12:36 p.m.

Thanks Nick.  My target directory for plugins is "client\eclipse\plugins". RTC shows that com.ibm.rational.connector.hudson.common is loaded, and it appears that it's coming from:

client\eclipse\plugins\com.ibm.rational.connector.hudson.common_1.0.400.v20130430_2233.jar

(I don't understand why the H/J build template isn't being listed by my code)

I do not see com.ibm.rational.connector.hudson.internal.common.HudsonConfigurationElement as being loaded, nor can I find it in either of these directories:

buildsystem\buildengine\eclipse\plugins
buildsystem\buildtoolkit
client\eclipse\plugins


Todd Strangio commented Jan 07 '14, 2:48 p.m.

Correction.


client\eclipse\plugins\com.ibm.rational.connector.hudson.common_1.0.400.v20130430_2233.jar

contains com.ibm.rational.connector.hudson.internal.common


Nick Edgar commented Jan 07 '14, 3:34 p.m.
JAZZ DEVELOPER

Need to distinguish between plugin IDs (com.ibm.rational.connector.hudson.common) and package names (com.ibm.rational.connector.hudson.internal.common) here. 


When you say your target directory is …\client\eclipse\plugins, is that your compile-time target or runtime target? How are you launching your code, and what is the class path at that time?  Are you running it as a plain Java application, or under OSGi/Equinox (e.g. as a contributed UI extension in the IDE)?  If the latter, is the plugin added as a prerequisite of yours?



Todd Strangio commented Jan 09 '14, 8:07 a.m.

Thanks so much for the assist, Nick  I've managed to get this working by adding the following JARs to my project's build path:


com.ibm.rational.connector.hudson.client_1.0.400.v20130502_0139.jar
com.ibm.rational.connector.hudson.common_1.0.400.v20130430_2233.jar
com.ibm.rational.connector.hudson.ui_1.0.400.v20130502_0139.jar

Then when I dump available templates, I find that the name of the Hudson/Jenkins template is in fact:

com.ibm.rational.connector.hudson.ui.buildDefinitionTemplate

From there, I'm able to get a handle to the H/J template without hitting an NPE using:

IBuildDefinitionTemplate HJtemplate = BuildConfigurationRegistry.getInstance().getBuildDefinitionTemplate("com.ibm.rational.connector.hudson.ui.buildDefinitionTemplate");

Thanks again for the help.


Nick Edgar commented Jan 09 '14, 1:33 p.m. | edited Jan 09 '14, 1:33 p.m.
JAZZ DEVELOPER

Good to hear, and thanks for marking this answered.  I looked into the NPE but it's apparently just due to passing the null template into initializeConfiguration. The lookup method does correctly return null if the template is not found.  We were missing unit tests for that though, so I've added them.

showing 5 of 6 show 1 more comments

Your answer


Register or to post your answer.


Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.