[closed] How to create an IBuildProperty object
The question has been closed for the following reason: "The question is answered, right answer was accepted" by rschoon Dec 11 '16, 6:15 a.m.
Accepted answer
- to create the new build property:
String buildPropName = ...
String buildPropValue = ...
IBuildProperty buildProp = BuildItemFactory.createBuildProperty();
buildProp.setKind(IBuildProperty.PROPERTY_KIND_STRING);
buildProp.setName(buildPropName);
buildProp.setValue(buildPropValue); - to retrieve the build definition:
ITeamRepository repo = ...
ITeamBuildClient buildClient = (ITeamBuildClient) repo.getClientLibrary(ITeamBuildClient.class);
String buildDefId = ...
IBuildDefinition buildDef = buildClient.getBuildDefinition(buildDefId, null);
7 other answers
Comments
Hi, I was able to modify the Build Properties section in the RTC client (By right clicking on build definition -> select Request Build".
ITeamBuildRequestClient.requestBuild(IBuildDefinitionHandle buildDefinitionHandle,
IBuildProperty[] newOrModifiedBuildProperties, IBuildProperty[] deletedBuildProperties, boolean allowDuplicateRequests, boolean personalBuild, IProgressMonitor progressMonitor)</pre>
The code above tries to update the actual build definition, not just the property in the build being requested. Each section in the request build dialog is implemented by a subclass of com.ibm.team.build.ui.dialogs.requestbuild.RequestBuildSection. Normally they apply their properties in the applyProperties(IBuildDefinition) method. Although this is passed a working copy of the build definition, the intent is just to capture any changes in build properties, which are then diff'ed with original build definition, and the deltas are passed on to the requestTeamBuild API (this is done internally, in com.ibm.team.build.internal.ui.dialogs.RequestBuildDialog.requestBuildJobImpl).
Thanks Nick. I don't want to update the build definition itself. Our goal is to submit a personal build through the java api, as if the approach as we log on to RTC client and request a build. In the RTC client user could modify parameters defined in build properties and build option section.
Yes, that's correct. The newOrModifiedBuildProperties will override any properties with the same names from the build definition. That is, the new request gets a copy of the build definition properties, plus newOrModifiedBuildProperties (taking priority), less deletedBuildProperties.
I used following code to retrieve the UUID of the repository workspace:
Try: ...getResolvedWorkspace().getItemId().getUuidValue().
Thanks Nick. It is working. I could now set both the repository workspace and build properties. However when I tried to set multiple properties, only the first element of BuildProperties[] has been reflected in the build. Here is the sample code:
Sorry please discard my previous question. Thanks.
Comments
Hi Sachin. The line:
IBuildProperties[1]= buildProp;
IBuildProperty[] buildProps = new IBuildProperty[] { buildProp };then pass it to requestBuild. You can also use the createBuildProperty method that takes name and value to simplify the code:
IBuildProperty buildProp = BuildItemFactory.createBuildProperty("workItemId", 31); IBuildProperty[] buildProps = new IBuildProperty[] { buildProp }; ITeamBuildRequestService brService = getService(ITeamBuildRequestService.class); IItemsResponse response = brService.requestBuild(buildDef, buildProps, null, true, false);
1 vote
Thanks Nick, its working fine
IBuildProperty x = new IBuildProperty();
x.setName(...);
x.setValue(....);
x.setDescription(...);
x.setKind(....);
x.setRequired(true/false);
also, 3.0.1.1 javadoc is now available.. very helpful overall.
Sam
Comments
Sam,
thanks for your reply. But I can't use directly new IBuildProperty (I got a "Cannot instantiate the type IBuildProperty" error), so do I have to implement the class as Eclipse suggest me?
Thanks,
Michele.
Looks like there is no custom constructor, so you would just do a normal new operation.. and then set the fields thru the set methods.
IBuildProperty x = new IBuildProperty();
x.setName(...);
x.setValue(....);
x.setDescription(...);
x.setKind(....);
x.setRequired(true/false);
also, 3.0.1.1 javadoc is now available.. very helpful overall.
Sam