It's all about the answers!

Ask a question

How to get the ITeamBuildService


Jia Jia Li (8057152192) | asked Sep 25 '12, 2:10 a.m.
edited Sep 25 '12, 4:28 a.m. by Ralph Schoon (63.1k33646)
Hi, I use the following code to get the   ITeamBuildService, but it has null value. the pa object is gotten. 
Do I use the wrong API? Please help. Thanks!

ITeamRepository repo = login(monitor);           
 IProjectArea pa = getProjArea(repo,monitor);
            
 ITeamBuildService service = (ITeamBuildService) repo.getClientLibrary(ITeamBuildService.class); 
 IBuildDefinition[] buildDefs = service.getBuildDefinitions();

Accepted answer


permanent link
sam detweiler (12.5k6195201) | answered Jan 08 '14, 9:31 a.m.
edited Jan 09 '14, 9:16 p.m.
 ok, here is the routine which will get the current set of build engines from a repo 
ugly programming model. this returns all the properties of each build engine. 
one could reduce the data if desired, by removing some of the properties in the
all_properties list

also provided is a routine to filter that by a specific project area. 
this needs the process_area property to be returned


private void processBuilds(ITeamRepository repo, IProjectArea owning_project)
{
for (IBuildEngine buildEngine : getBuildEngines(repo)) {
if(buildEngine.getProcessArea().sameItemId(owning_project))
System.out.println(buildEngine.getId()+ " = "+ buildEngine.getDescription());
}
}
private  ArrayList<IBuildEngine> getBuildEngines(ITeamRepository repo)
{
// allocate space for results
ArrayList<IBuildEngine> allbe=new ArrayList<IBuildEngine>();
// get the data interface
ITeamBuildClient  buildClient = (ITeamBuildClient) repo
.getClientLibrary(ITeamBuildClient.class);

try
{
IBuildEngineQueryModel queryModel = IBuildEngineQueryModel.ROOT;
// create a query for build engines
IItemQuery query = IItemQuery.FACTORY.newInstance(queryModel);
// objects of build engine type
IPredicate isBuildEngineType = queryModel._isTypeOf(IBuildEngine.ITEM_TYPE);
// the query filter
query.filter(isBuildEngineType);
// no parameters required
IItemQueryPage queryPage = buildClient.queryItems(query, 
com.ibm.team.repository.common.service.IQueryService.EMPTY_PARAMETERS,
   IQueryService.ITEM_QUERY_MAX_PAGE_SIZE, null);
// if there are buildengines defined
if (queryPage.getResultSize() != 0) {

while (queryPage != null) {

// print out a page of IDs of the retrieved build engines
final String[] all_properties = new String[] {
IBuildEngine.PROPERTY_ACTIVE,
IBuildEngine.PROPERTY_BUILD_ENGINE_ACTIVITY,
IBuildEngine.PROPERTY_DESCRIPTION,
IBuildEngine.PROPERTY_ENGINE_CONTACT_INTERVAL,
IBuildEngine.PROPERTY_ID ,
IBuildEngine.PROPERTY_PROCESS_AREA,
IBuildEngine.PROPERTY_SUPPORTED_BUILD_DEFINITIONS,
IBuildEngine.PROPERTY_SUPPORTS_CANCELLATION,
IBuildEngine.PROPERTY_USE_TEAM_SCHEDULER,
IBuildEngine.PROPERTY_PROPERTIES,
IBuildEngine.PROPERTY_CONFIGURATION_ELEMENTS
};
IFetchResult fetchResult = repo.itemManager().fetchPartialItemsPermissionAware(queryPage.getItemHandles(), IItemManager.DEFAULT,
Arrays.asList(all_properties), null);
// add these to the list
allbe.addAll(fetchResult.getRetrievedItems());

if (queryPage.hasNext()) {
queryPage = (IItemQueryPage) buildClient.fetchPage(queryPage.getToken(), queryPage.getNextStartPosition(), queryPage.getSize(), null);
} else {
queryPage = null;
}

}
}
}
catch (Exception ex)
{
System.out.println("build exception="+ex.getMessage());
}
return allbe;
}
Ralph Schoon selected this answer as the correct answer

Comments
Ralph Schoon commented Jan 08 '14, 10:23 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Sam, thanks so much for sharing!

I will try to blog about this, so others can use it too.


sam detweiler commented Jan 08 '14, 10:43 a.m. | edited Jan 08 '14, 10:44 a.m.

my pleasure..


supposedly there is a way to use the query filter with the _in predicate to filter based on project area, instead of the code loop in the above.  but I haven't figured it out yet. 
(get 0 results). 

one argument
<code>
IPredicate filter = queryModel._in(new IItemHandleInputArg[] {query.newItemHandleArg()});
IItemQueryPage queryPage = buildClient.queryItems(query,
new Object[]{project_area_handle},
IQueryService.ITEM_QUERY_MAX_PAGE_SIZE, null);
</code>


Ralph Schoon commented Jan 08 '14, 10:45 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

That is used in my code snippet. I will try to find out how it works.


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

 yes, your snippet is using BuildDefinitions not BuildEngines.


build defs have a processarea() method. engines do not

2 other answers



permanent link
Ralph Schoon (63.1k33646) | answered Sep 25 '12, 5:47 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
Jia,

please have a look into the JavaDoc of the Plain Java client library and try to use the basic search functionality in the Eclipse PDE with Eclipse set up for SDK and Plain Java development (see my article on how to).

 I could find a method to get the build definitions from the ITeamBuildClient in less than 3 minutes. This is a client library that you cen get using getClientLibrary().

Comments
sam detweiler commented Jan 07 '14, 5:34 p.m.

Ok, you are better than me. I cannot find a method to get the list of build engines or builds. 

I can see the source for ITeamBuildClient and ITeamBuildService, and I can search, but don't see what I would be searching on. (or where)..


Ralph Schoon commented Jan 08 '14, 3:41 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Ralph Schoon commented Jan 08 '14, 4:40 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

I dug a bit deeper. I was also not able to instantiate the ITeamBuildService. The implementation of TeamBuildClient implements a getService() method that is private and does not appear in ITeamBuildClient to get the ITeamBuildService.

    private ITeamBuildService getService() {
        return (ITeamBuildService) getContext().getServiceInterface(ITeamBuildService.class);
    }

I think Jia did what you attempt as well, maybe she has a better answer. Otherwise I would suggest to use the https://jazz.net/wiki/bin/view/Main/BuildJavaProgrammingExamples to get at the data you need and then try to dig deeper.


sam detweiler commented Jan 08 '14, 6:33 a.m.

yes, I saw that in the buildclient code.  Your prior note link shows how to get build engines for a build def. nice, but then I need all buid defs..  :-)

i need to copy everything. build engines are supposedly the top of the tree.


Ralph Schoon commented Jan 08 '14, 6:41 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Sam, i have not the time today to poke through the API. You might be able to find query examples and be able to query for what you are looking at. Jia might be able to provide some hints.


sam detweiler commented Jan 08 '14, 6:48 a.m.

I do not expect u to spend time to research solutions for me.
thanks for the pointers..

there is a ton of pressure to get this project moved from their old 3.0.1 system to the production landscape on 4.0.4. like week before last.. I've got everything but builds, and my coworker is building the links reconstruction tool and he is close as well.


Ralph Schoon commented Jan 08 '14, 9:03 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

I think in my answer I refered to

ITeamBuildClient teamBuildClient = (ITeamBuildClient) teamRepository.getClientLibrary(ITeamBuildClient.class);
teamBuildClient.getBuildDefinition(buildDefinitionId, monitor);

Unfortunately, this does only provide you with what you want, if you know the ID already.

showing 5 of 7 show 2 more comments

permanent link
Ralph Schoon (63.1k33646) | answered Sep 25 '12, 3:49 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
edited Sep 25 '12, 4:28 a.m.
Jia, please download the javadoc for the Plain Java Client Libraries. You will notice that the service you refer to is not available there. It is a server side service. So you can't get it as a client library. See https://jazz.net/library/article/807 for more information on the API.

I would assume you have to use the ITeamBuildClient.

Comments
Jia Jia Li commented Sep 25 '12, 5:22 a.m.

Thanks for your information Ralph. My requirement is to get all the build definitions. I find ITeamBuildService has the getBuildDefinitions() function. So I asked how to get ITeamBuildService object. Or if you know any other method to get all the build definitions, it is useful for me. Thanks !


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.