Rehashing RTC Build Definition programmatically
Hello,
Is it possible to get the list of Build definitions (I'm using Build Forge engine) for an RTC project and rehash them programmatically?
Every time something changes in the Build Forge definition, one needs to re-save the RTC build definition in order for the changes to take place.
Thank you in advance for any help
Is it possible to get the list of Build definitions (I'm using Build Forge engine) for an RTC project and rehash them programmatically?
Every time something changes in the Build Forge definition, one needs to re-save the RTC build definition in order for the changes to take place.
Thank you in advance for any help
Accepted answer
yes and yes..
here is a routine to find build defs in a project
private static ArrayList<IBuildDefinition> getBuildDefinitionsforProjectArea(
IProjectAreaHandle iprja)
{
Boolean allProperties = true;
// allocate space for results
ArrayList<IBuildDefinition> allbd = new ArrayList<IBuildDefinition>();
ITeamRepository repo = (ITeamRepository) iprja.getOrigin();
// get the data interface
ITeamBuildClient buildClient = (ITeamBuildClient) repo.getClientLibrary(ITeamBuildClient.class);
try
{
IBuildDefinitionQueryModel queryModel = IBuildDefinitionQueryModel.ROOT;
// create a query for build engines
IItemQuery query = IItemQuery.FACTORY.newInstance(queryModel);
// objects of build engine type
IPredicate isBuildDefType = queryModel._isTypeOf(IBuildDefinition.ITEM_TYPE);
// allocate space for the parameter
IItemHandleInputArg[] itemHandleArgs = new IItemHandleInputArg[] { query.newItemHandleArg() };
// the query filter
IPredicate filter = ((BuildDefinitionQueryModel) queryModel).processArea()._in(itemHandleArgs);
// set the combined filter
query.filter(filter._and(isBuildDefType));
// no parameters required
IItemQueryPage queryPage = buildClient.queryItems(query,
// com.ibm.team.repository.common.service.IQueryService.EMPTY_PARAMETERS,
new Object[] { iprja }, IQueryService.ITEM_QUERY_MAX_PAGE_SIZE, null);
// if there are build definitions defined
if (queryPage.getResultSize() != 0)
{
while (queryPage != null)
{
IFetchResult fetchResult = null;
if (allProperties == true)
{
fetchResult = repo.itemManager().fetchCompleteItemsPermissionAware(queryPage.getItemHandles(), IItemManager.DEFAULT, null);
}
else
{
// print out a page of IDs of the retrieved build definitions
// needs to be fixed for build defs
final String[] all_properties = new String[] {
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 };
fetchResult = repo.itemManager().fetchPartialItemsPermissionAware(queryPage.getItemHandles(), IItemManager.DEFAULT, Arrays.asList(all_properties), null);
}
// add these to the list
allbd.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 allbd;
}
here is a routine to find build defs in a project
private static ArrayList<IBuildDefinition> getBuildDefinitionsforProjectArea(
IProjectAreaHandle iprja)
{
Boolean allProperties = true;
// allocate space for results
ArrayList<IBuildDefinition> allbd = new ArrayList<IBuildDefinition>();
ITeamRepository repo = (ITeamRepository) iprja.getOrigin();
// get the data interface
ITeamBuildClient buildClient = (ITeamBuildClient) repo.getClientLibrary(ITeamBuildClient.class);
try
{
IBuildDefinitionQueryModel queryModel = IBuildDefinitionQueryModel.ROOT;
// create a query for build engines
IItemQuery query = IItemQuery.FACTORY.newInstance(queryModel);
// objects of build engine type
IPredicate isBuildDefType = queryModel._isTypeOf(IBuildDefinition.ITEM_TYPE);
// allocate space for the parameter
IItemHandleInputArg[] itemHandleArgs = new IItemHandleInputArg[] { query.newItemHandleArg() };
// the query filter
IPredicate filter = ((BuildDefinitionQueryModel) queryModel).processArea()._in(itemHandleArgs);
// set the combined filter
query.filter(filter._and(isBuildDefType));
// no parameters required
IItemQueryPage queryPage = buildClient.queryItems(query,
// com.ibm.team.repository.common.service.IQueryService.EMPTY_PARAMETERS,
new Object[] { iprja }, IQueryService.ITEM_QUERY_MAX_PAGE_SIZE, null);
// if there are build definitions defined
if (queryPage.getResultSize() != 0)
{
while (queryPage != null)
{
IFetchResult fetchResult = null;
if (allProperties == true)
{
fetchResult = repo.itemManager().fetchCompleteItemsPermissionAware(queryPage.getItemHandles(), IItemManager.DEFAULT, null);
}
else
{
// print out a page of IDs of the retrieved build definitions
// needs to be fixed for build defs
final String[] all_properties = new String[] {
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 };
fetchResult = repo.itemManager().fetchPartialItemsPermissionAware(queryPage.getItemHandles(), IItemManager.DEFAULT, Arrays.asList(all_properties), null);
}
// add these to the list
allbd.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 allbd;
}
Comments
Thanks Sam. I can get the list of build definitions!
Which method should I invoke now for each IBuildDefinition instance to rehash them?
Thank you
sorry does 'rehash' mean save?
I save the build engine with related build defs
ITeamBuildClient buildClient = (ITeamBuildClient) repo.getClientLibrary(ITeamBuildClient.class);
buildClient.save(buildEngine_new, null);
same call for defs
buildClient.save(newbuildDef, null);
Thanks Sam -
The issue I'm having is with the synchronization between Build Forge and RTC build definition. For instance when I change an environment variable on Build Forge, the change is not reflected in the RTC Build definition. I need to connect it to some random BF project, save, then connect to the real one and save again for the changes to be reflected in RTC Build Definition. I was hoping that re-saving the RTC build Definition will update the Build Forge env variables but it doesn't, hence the need to "rehash" the RTC build definition.
Any idea how to force an refresh from Build Forge to RTC build definition?
Thanks
sorry, no idea.