Possible to create Hudson/Jenkins build def via API?
![]()
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.
showing 5 of 6
show 1 more comments
|
Accepted answer
![]()
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 You can grab those plugins from the RTC Eclipse client. 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
Correction.
client\eclipse\plugins\com.ibm.rational.connector.hudson.common_1.0.400.v20130430_2233.jar
contains com.ibm.rational.connector.hudson.internal.common
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?
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.
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
|
Comments
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.
yeh, there are two different registry's.. what happens if you dump the other
Build Engine Template Info:
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
Thanks Sam, but still no dice. Appreciate the attempt.