Jenkins Code to Connect to RTC to fetch Build Definition
Hello Everyone,
I am writing a Jenkins plug-in to connect to Rational Team concert to validate and fetch source code from a Build Definition. In order to do this, I would require User ID and password as input from the user. I would like to know if there is any API for RTC which would perform this task? Any inputs would be extremely helpful. |
One answer
there is no 'direct' api to get the list of build engines or build definitions.. you use query for that
here is a routine I wrote to get the build definitions in a project. I assume you know how to use the plainjava api to logon, etc.. private static ArrayList<IBuildDefinition> getBuildDefinitionsforProjectArea( IProjectAreaHandle iprja) { Boolean allProperties = true; // allocate space for results ArrayList<IBuildDefinition> allbe = 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 // 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 }; 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; } |
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.
Comments
Sriram Sundaresan,
Is there any technical reason why you need to roll your own Jenkins plug-in for the basic activities of validating/fetching code based on a RTC Build Definition?
IBM's official Rational Team Concert plugin already integrates with a build definition to pull source, just wanted to make sure you weren't trying to write a custom one as the older versions of IBM's RTC Jenkins plugin didn't work with build definitions.
As sam detweiler already pasted, you can write all the plumbing to get that data, I also believe there is an area in the API to use/decrypt the encrypted JBE password files, that way you don't need to hardcode the user/pass inside the plugins or as args to it.