Search code examples
powershelltfsbuildtfs-2015

Filter out Private Builds


We're upgrading our Xaml builds from TFS 2010 to the vNext build definitions in TFS 2015. As part of this, we have a few processes that monitor the builds. These processes filter out the Private builds (i.e. those running against a shelveset without committing the changes on success).

In the new definitions, I'm having a hard time figuring out how to identify these types of builds. When I look at the Reason on the build, its set to Manual, rather than (as I expected) ValidateShelveset.

Whats the best way to identify these private builds from the REST api?


Solution

  • For Vnext build, queue build with a shelveset doesn't recognized as a private build. The build reason is "Manual".

    Based on my test, the sourcebranch is different with other Manual or BatchedCI builds, So to identify the builds against shelveset, we can check the "sourceBranch".

    Use the REST API to check the build details (attributes):eg

    GET http://server:8080/tfs/CollectionLC/TFVC-ScrumSample/_apis/build/builds/1027?api-version=2.0 
    

    You can use below sample code to get the builds, then check the sourceBranch to identify the shelveset builds:

    using System;
    using Microsoft.TeamFoundation.Build.WebApi;
    using Microsoft.VisualStudio.Services.Client;
    
    namespace GetBuilds
    {
        class Program
        {
            static void Main(string[] args)
            {
                var tfsUrl = " http://server:8080/tfs/Collection";
                var buildClient = new BuildHttpClient(new Uri(tfsUrl), new VssAadCredential());
                var builds = buildClient.GetBuildsAsync("YourProjectName");
    
                foreach (var build in builds.Result)
    
                {
                    Console.WriteLine(String.Format("{0} - {1} - {2} - {3}", build.Definition.Name, build.Id.ToString(), build.Status.ToString(), build.SourceBranch.ToString()));
                }
            }
        }
    }
    

    For other "Private" builds, you can also check the build attributes and find out the different with others, then get them accordingly.

    enter image description here