It's all about the answers!

Ask a question

Copy Builds and BuildDefinition via api, question. RESOLVED

sam detweiler (12.5k6195201) | asked Jan 08 '14, 3:25 p.m.
edited Jan 09 '14, 9:54 a.m.
 Unfortunately I am working on a copyproject function. one element is the build engines and builds. 

I now can loop thru the data on the source server, and am starting to replicate the data (which there appears to be a LOT of). 

Buildengine has a copyEngine() and BuildDef has a copyDefintion() functions.  These appear to be deep copy, but of course embedded handles are copied intact.  those handles of course are useless on the new repository. 

Is there any documented tree of the objects down from build engine, that shows (object) handle relationships?
(that I can look at?)

oh, and I want to say, there is a very dangerous issue with adding a Builddef to a build engine supported list. 
assuming that the list<> object is persistent outside the object is really nasty.  (not to mention hard to learn)

one is depending that the value returned by getSupportedBuildDefinitions() is passed by reference and not by value.
this should have been encapsulated in the BuildEngine object with an addSupportedBuildDef(bd) method.
(and this design should be consistent across all the objects.. matching get/set methods). 

Accepted answer

permanent link
sam detweiler (12.5k6195201) | answered Jan 09 '14, 8:44 a.m.
edited Jan 09 '14, 9:11 p.m.
as a followon question (have to put this in an 'answer' cause of the size.)
I am successfully creating build engines and build definitions. 
BuildDef only has the overview page successfully built. 
if you add the schedule info the build def, it shows!!. doah!.. corrected below in bold 
you have to copy the properties too!.  corrected below in bold

I process all the data for schedules and all the other tabs, but that data is not saved in the buildDef..  

I looked thru the Eclipse UI code for creating engines and defs and don't 'see' anything special about the sub pages. 

I do not 'initialize' the builddef, cause I don't know what template it came from, I just copy data from the prod server instance to the dev server instance. 
here is my clone builddef function

private static IBuildDefinition cloneBuildDef(ITeamRepository devrepo, IBuildDefinition oldbuildDef, IProcessAreaHandle new_project)
ITeamBuildClient  buildClientdev = (ITeamBuildClient) devrepo
// create a new build definition connected to the new project area
IBuildDefinition newbuildDef = BuildItemFactory.createBuildDefinition((IProcessArea) new_project);
try {
newbuildDef.setId(oldbuildDef.getId()); // worked
newbuildDef.setDescription(oldbuildDef.getDescription()); // worked
// process the build pruning info 
IBuildResultPruningPolicy ppp = BuildItemFactory.createBuildResultPruningPolicy();
// process the build schedule info
IBuildSchedule pppp = BuildItemFactory.createBuildSchedule();
ArrayList<IBuildScheduleEntry> entrylist = new ArrayList<IBuildScheduleEntry>();
for(IBuildScheduleEntry ppppp: (List<IBuildScheduleEntry>)oldbuildDef.getBuildSchedule().getBuildScheduleEntries())
IBuildScheduleEntry newschedentry = BuildItemFactory.createBuildScheduleEntry();
System.out.println("build schedule entry time="+newschedentry.getBuildHour()+":"+newschedentry.getBuildMinute());

// process the build configuration data
for(IBuildConfigurationElement buildConfElem:(List<IBuildConfigurationElement>)oldbuildDef.getConfigurationElements())

System.out.println("\t\tBuild Config element name="+buildConfElem.getName());
IBuildConfigurationElement newconfElem = BuildItemFactory. createBuildConfigurationElement();
for (IConfigurationProperty buildConfigProperty : (List <IConfigurationProperty>) buildConfElem.getConfigurationProperties())
String name = buildConfigProperty.getName();
String value = buildConfigProperty.getValue();
IConfigurationProperty new_ibcp = BuildItemFactory.createConfigurationProperty(name, value);
System.out.println("\t\t\tname:" + name + "---value:" + value);
System.out.println("there are now "+newconfElem.getConfigurationProperties().size()+" properties");
// copy all the properties
for(IBuildProperty bdp :(List<IBuildProperty>)oldbuildDef.getProperties())
newbuildDef.setProperty(bdp.getName(), bdp.getValue());
// save the new build definition,null);
catch (Exception e) 
// TODO Auto-generated catch block
System.out.println("clone definition error = "+e.getMessage());
return newbuildDef;
Ralph Schoon selected this answer as the correct answer

sam detweiler commented Jan 09 '14, 9:02 a.m. | edited Jan 09 '14, 9:09 a.m.

also, how do you know  what timezone a buildscheduleentry is using? local or GMT?

when I pull the data out, it shows 
build schedule entry time=8:15
build schedule entry time=18:15
but in the build def UI it shows 3:15am(8-5=3) and 1:15pm(18-5=13=1pm)

never mind, doesn't matter if u save the data!

One other answer

permanent link
sam detweiler (12.5k6195201) | answered Jan 09 '14, 9:54 a.m.
 can someone mark this resolved.. accept my answer with the code sample..


Your answer

Register or to post your answer.