It's all about the answers!

Ask a question

[closed] How to create an IBuildProperty object


Michele Pegoraro (1.8k12114101) | asked Nov 18 '11, 9:29 a.m.
closed Dec 11 '16, 6:15 a.m. by Ralph Schoon (58.2k23642)
Hi,
I was searching for a method to create a new IBuildProperty object in order to add it to a build request. I can't find any "new" methods or factory class.

Does someone knows how to create this object?

NB: I'm working on server side.

Thanks,
Michele.

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


permanent link
SEC Servizi (97122547) | answered Jun 11 '12, 5:00 a.m.
edited Jun 11 '12, 5:07 a.m.
We would add a new build property to some existing build definitions using a Plain Java Client.
We are able:
  1. 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);
  2. to retrieve the build definition:
    ITeamRepository repo = ...
    ITeamBuildClient buildClient = (ITeamBuildClient) repo.getClientLibrary(ITeamBuildClient.class);
    String buildDefId = ... 
    IBuildDefinition buildDef = buildClient.getBuildDefinition(buildDefId, null);
How can we now add IBuildProperty buildProp to IBuildDefinition buildDef?
Thanks in advance.
Jared Burns selected this answer as the correct answer

Comments
1
SEC Servizi commented Jun 11 '12, 9:56 a.m. | edited Jun 13 '12, 4:05 p.m.

Ok, it was quite simple:

IBuildDefinition buildDefFreshCopy = (IBuildDefinition) buildDef.getWorkingCopy();
List<IBuildProperty> buildProps = buildDefFreshCopy.getProperties(); 
buildProps.add(buildProp);
buildClient.save(buildDefFreshCopy, null);

Cheers.

7 other answers



permanent link
Michele Pegoraro (1.8k12114101) | answered Nov 21 '11, 6:22 a.m.
I've found the right method:

BuildItemFactory.createBuildProperty();


Thanks,
Michele.

Comments
Nick Edgar commented Dec 01 '11, 11:27 p.m. | edited Jun 13 '12, 4:04 p.m.
JAZZ DEVELOPER

Yes, that's the correct API to use. Note that since 3.0 you can also use:
com.ibm.team.build.common.BuildItemFactory.createBuildProperty(String name, String value)


permanent link
Nick Edgar (6.5k711) | answered Jun 13 '12, 3:01 p.m.
JAZZ DEVELOPER
You can also use:
com.ibm.team.build.common.model.IBuildDefinition.setProperty(String, String)
which will add the property if not already there, or override its value if it is.
It still needs to be called on a working copy of the item.

Comments
Nick Edgar commented Jun 13 '12, 3:02 p.m.
JAZZ DEVELOPER

Hm, turns out I already said that back in December.


permanent link
Kelvin Lui (51299) | answered Aug 13 '13, 5:01 p.m.
 Could we use IBuildProperty to set the Repository Workspace (for personal build) which is under the Build Options section?

Thanks.

permanent link
Kelvin Lui (51299) | answered Aug 13 '13, 5:03 p.m.
 Could we use IBuildProperty to set the Repository workspace (for personal build), which is under the Build Options?  Thanks.

permanent link
Nick Edgar (6.5k711) | answered Aug 13 '13, 9:46 p.m.
JAZZ DEVELOPER
@Kelvin, you asked:
Could we use IBuildProperty to set the Repository Workspace (for personal build) which is under the Build Options section?

Yes, when you request a personal build, it overrides the "team.scm.workspaceUUID" property with the item id for the selected developer workspace.  This is the same property used for non-personal builds (as indicated in the description for the workspace field in the SCM page of the build definition).  In the case of a personal build, its value just gets changed to refer to the selected workspace.

Comments
Kelvin Lui commented Aug 14 '13, 10:50 a.m. | edited Aug 14 '13, 12:21 p.m.

 Hi,  I was able to modify the Build Properties section in the RTC client (By right clicking on build definition -> select Request Build".


However when I tried the code above to modify the Build Properties:
IBuildDefinition buildDefFreshCopy = (IBuildDefinition) buildDef.getWorkingCopy();
List<IBuildProperty> buildProps = buildDefFreshCopy.getProperties(); 
buildProps.add(buildProp);
buildClient.save(buildDefFreshCopy, null);

I hit the following permission error:
Unable to login: CRJAZ6053E The 'Save Build Definition' operation cannot be completed. Permission is required to complete the operation. For more details, open the help system and search for CRJAZ6053E.

I think it would be the same permission to modify/update the Build properties in either RTC client or through a java API.  Is my assumption incorrect?  

Would the code above only update/modify the working copy of the build definition Build properties and reflect in that specific Build, rather than actually update/modify the default Build properties value defined in the build definition?.   I used the following api to request a build afterwards:

ITeamBuildRequestClient.requestBuild(IBuildDefinitionHandle buildDefinitionHandle,

                           IBuildProperty[] newOrModifiedBuildProperties,
                           IBuildProperty[] deletedBuildProperties,
                           boolean allowDuplicateRequests,
                           boolean personalBuild,
                           IProgressMonitor progressMonitor)

</pre>

Thanks.


Nick Edgar commented Aug 14 '13, 12:27 p.m.
JAZZ DEVELOPER

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).


It would help to know what you're trying to achieve at a higher level.  I might be able to provide more concrete suggestions then.


Kelvin Lui commented Aug 14 '13, 3:03 p.m.

 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.


I identify the api ITeamBuildRequestClient.requestBuild which is to submit a build request.

Can you please show me the api where I could provide customized parameters to this build API, as if we could define in the GUI?   Would that be as simple as constructing the  IBuildProperty[] newOrModifiedBuildProperties and passing in as the api parameter?

Thanks.


Nick Edgar commented Aug 14 '13, 5:10 p.m.
JAZZ DEVELOPER

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.


Kelvin Lui commented Aug 14 '13, 6:20 p.m.
Thanks Nick, I figured out how to override Build properties parameter.  However still hit an issue to override the repository workspace:

I create the IBuildProperty and set the repository workspace
buildProp.setName("team.scm.workspaceUUID");
buildProp.setValue(_workspaceuuid.toString());
IBuildProperties[1]= buildProp;

Then I passed IBuildProperties to 
ITeamBuildRequestClient.requestBuild

and get the following error:
com.ibm.team.build.common.TeamBuildException: CRRTC3503E: The given workspace UUID "[UUID _Dp6kMdwTEd2jUupDpQV1Rw]" is not a valid UUID

Kelvin Lui commented Aug 14 '13, 6:20 p.m.

 I used following code to retrieve the UUID of the repository workspace:


IWorkspaceSearchCriteria workspaceSearchCriteria = IWorkspaceSearchCriteria.FACTORY.newInstance();
workspaceSearchCriteria.setPartialName(workspaceName);
workspaceSearchCriteria.setKind(WorkspaceSearchCriteria.ALL);
IWorkspaceHandle workspaceHandle = IWorkspaceManager findWorkspaces(workspaceSearchCriteria, Integer.MAX_VALUE, null).get(0);
IWorkspaceConnection workspace_connection = IWorkspaceManager.getWorkspaceConnection(workspaceHandle, null);
return workspace_connection.getResolvedWorkspace().getContextId();


Nick Edgar commented Aug 15 '13, 8:57 a.m.
JAZZ DEVELOPER

Try: ...getResolvedWorkspace().getItemId().getUuidValue().

getContextId() returns the context id, which is different than the item id.  It's used for read access control, and is usually the project area item id.


Kelvin Lui commented Aug 15 '13, 1:06 p.m.

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:




Kelvin Lui commented Aug 15 '13, 1:14 p.m.

Sorry please discard my previous question.  Thanks.

showing 5 of 9 show 4 more comments

permanent link
Sachin Nairy (5111118) | answered Dec 11 '16, 4:04 a.m.
 Hi, 
I have wrote server side API to trigger build on work item save.

Also I am passing worksitem id to build as Property.
I have created string type of property “workItemId” in build definition, now I have to  pass the value for this property with workitem id.
Could you please suggest some solution, I tried with below code but while creating IBuildProperties[1], I am getting IBuildProperties cannot be resolved to a variable error message


IBuildProperty buildProp = BuildItemFactory.createBuildProperty();
buildProp.setName("workItemId");
buildProp.setValue("31");
buildProp.setKind(IBuildProperty.PROPERTY_KIND_STRING);
IBuildProperties[1]= buildProp;
ITeamBuildRequestService brService = getService(ITeamBuildRequestService.class);
IItemsResponse response = brService.requestBuild(buildDef, IBuildProperties[1], null,true, false);

Comments
1
Nick Edgar commented Dec 11 '16, 12:43 p.m. | edited Dec 11 '16, 12:50 p.m.
JAZZ DEVELOPER

Hi Sachin. The line:

IBuildProperties[1]= buildProp;
is invalid -- there is no such class or variable name. To create an array with the build property, use:
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);


Sachin Nairy commented Dec 11 '16, 2:51 p.m.

 Thanks Nick, its working fine


-1
permanent link
sam detweiler (12.4k6180201) | answered Nov 18 '11, 11:25 a.m.
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

Comments
Michele Pegoraro commented Nov 21 '11, 5:01 a.m. | edited Jun 13 '12, 4:03 p.m.

Sam,
thanks for your reply. But I can't use directly new IBuildProperty (I got a &quot;Cannot instantiate the type IBuildProperty&quot; 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