[closed] How to create an IBuildProperty object
Michele Pegoraro (1.8k●14●119●103)
| asked Nov 18 '11, 9:29 a.m.
closed Dec 11 '16, 6:15 a.m. by Ralph Schoon (63.3k●3●36●46)
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
7 other answers
Could we use IBuildProperty to set the Repository Workspace (for personal build) which is under the Build Options section?
Thanks.
|
Could we use IBuildProperty to set the Repository workspace (for personal build), which is under the Build Options? Thanks.
|
@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 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)
Thanks.
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.
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();
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
|
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
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);
Sachin Nairy
commented Dec 11 '16, 2:51 p.m.
Thanks Nick, its working fine |