How can I find the latest build in the BuildDrop location?
Question
I've defined a build in TFS 2010 with a drop location like "\server\BuildDrop\". When I queue the build, it drops the build in something like "\server\BuildDrop\MyBuild\MyBuild_20120309.1".
I'd like to be able to define a build that will drop at an exact location that never changes. Can I change the build definition to always drop at a location like this?
1) \server\BuildDrop\MyBuild\
or
2) \server\BuildDrop\MyBuild\Latest\
Solution
If people want to know where to find the latest builds, I think it is best to educate them on where the drop location is and what the build names are so they can easily determine which one is the latest themselves. If you want to copy the output of the drop location to the same directory, you would have to create a custom template (by modifying the default template) that runs your build. During my build, after the files are copied to the drop location I execute a script to copy the files in the drop location to a common "Latest" directory. However, you can easily run into problems where people are accessing files in the "Latest" directory while you are running a build, and so your build fails because it cannot overwrite those files.
If you want to determine the drop location of the last successful build you can also do it programmatically. Below is a snippet of a custom activity I wrote to do just that:
string tfsUri = "http://pathToTfsServer:8080/tfs";
string projectName = "MyTfsProject";
string buildDefinition = "MyTfsBuildDefinitionName";
// connect to the Project and query the builds of the BuildDefinition
var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(tfsUri), new UICredentialsProvider());
tfs.EnsureAuthenticated();
var buildServer = tfs.GetService<IBuildServer>();
var buildDetails = buildServer.QueryBuilds(projectName, buildDefinition);
// sort builds based on start time
Array.Sort(buildDetails, delegate(IBuildDetail build1, IBuildDetail build2)
{
return build1.StartTime.CompareTo(build2.StartTime);
});
// return only the last successful build that currently exists
for (int i = buildDetails.Length - 1; i >= 0; i--)
{
if (buildDetails[i].Status == BuildStatus.Succeeded && buildDetails[i].IsDeleted == false)
return buildDetails[i];
}
If you are looking at customizing Team Build 2010 then I suggest reading Ewald Hoffman's tutorials on the subject.
OTHER TIPS
When a build is triggered, a folder will be created in the specified drop location like
- MyBuild_20120309.1
- MyBuild_20120309.2
- MyBuild_20120310.1
Folder naming convention is "Build Definition"_"yyyymmdd"."build number"
build number is the number of builds given in a day. So when you trigger a build, you can go the build drop location and just go the the latest folder (based on the naming convention) and get the setup.