Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

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

0 votes


Accepted answer

Permanent link
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;
    }
EclipseTalk . selected this answer as the correct answer

2 votes

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.

Your answer

Register or log in 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.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 562

Question asked: Feb 04 '15, 10:09 a.m.

Question was seen: 4,323 times

Last updated: Feb 05 '15, 11:40 a.m.

Confirmation Cancel Confirm