Freigeben über


Average Build Size

So, I haven't actually gotten a request for this, but I thought it might be useful :)

This entry is based on Team Build's next version which is available in a CTP release right now, and will be in Beta very soon (don't ask, I don't know when). In the next version of Team Build, we have included an Object Model (OM) that wraps all the functionality of the Web Services. This makes writing your own apps that need build information, much easier.

Let's say you are using the new features of Team Build like drop management and continuous integration. So far you have the binaries for 12 builds sitting on your server for definition X. You notice you are almost out of disk space on that server and need to purchase some more. But how much? After looking at your drop managment policy for definition X, you see that the maximum number of builds you will need to keep is 20. But how much disk space does that correspond to? You could go to the drop location and sum up the size of every folder, but is there a faster way? Of course there is!

In the following PowerShell script, I get the list of builds for definition X and then sum up the size of all files in the drop locations.

> [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Client")
> [void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.TeamFoundation.Build.Client")
> $tfs = [Microsoft.TeamFoundation.Client.TeamFoundationServerFactory]::GetServer("https://server:8080/")
> $buildserver = $tfs.GetService([Microsoft.TeamFoundation.Build.Client.IBuildServer])
> $buildspec = $buildserver.CreateBuildDetailSpec()
> $buildspec.DefinitionPath = "\teamproject\CSharp_Tests"
> $buildspec.BuildNumber = "*"
> $queryResult = $buildserver.QueryBuilds($buildspec)
> $queryResult.Builds  | foreach { Get-ChildItem $_.droplocation -force -recurse | measure-object length -sum } | measure-object sum -average -sum

Count    : 4
Average  : 341554
Sum      : 1366216
Maximum  :
Minimum  :
Property : Sum

The most complicated part of the script is the last line that sums and averages everything. This could be a little simple, but I had some issues using the normal foreach ($b in $queryResult.Buidls). Piping the builds into the foreach uses a slightly different version of that command and worked better in this case. Basically, that line loops over the builds, calls Get-ChildItem recursively for all the files in the drop location (even hidden files, that's the -force options) and sums up the length property of all the files. Finally, it averages and sums the list of file length sums and reports on that result.

I hope some one finds this information useful!

Comments

  • Anonymous
    March 22, 2007
    Rob Caron on Team System Basics Training (200-Level), March 2007 Release and Application Lifecycle Management...

  • Anonymous
    March 22, 2007
    Jason Prickett , a developer on Team Build, has written some very nice posts. All of these posts only