0
votes

I want insight into whether developers are using gated builds for check-ins. Does the TFS object model allow you to associate a check-in/changeset with a build definition? I eventually want to be able to say:

Changeset   Gated?   Build defn
-------------------------------
123          0        NULL
456          1       dev-gated-defn
1

1 Answers

2
votes

You can use the TFS API to get this information. Below is an example method to demonstrate how you can write out the details you are interested in for the previous seven days (you can modify the MinFinishTime to change the time period).

    /// <summary>
    /// Writes out information about whether gated builds are being used.
    /// </summary>
    private static void _GetBuildInsights()
    {
        using (TeamProjectPicker tpp = new TeamProjectPicker(TeamProjectPickerMode.SingleProject, false, new UICredentialsProvider()))
        {
            if (tpp.ShowDialog() == DialogResult.OK)
            {
                TfsTeamProjectCollection projectCollection = tpp.SelectedTeamProjectCollection;
                var buildServer = projectCollection.GetService<IBuildServer>();

                var buildSpec = buildServer.CreateBuildDetailSpec(tpp.SelectedProjects[0].Name);
                buildSpec.InformationTypes = null;
                buildSpec.MinFinishTime = DateTime.Now.AddDays(-7);  // get last seven days of builds

                IBuildDetail[] builds = buildServer.QueryBuilds(buildSpec).Builds;

                Console.WriteLine("Changeset   Gated?   Build defn");
                Console.WriteLine("-------------------------------");

                foreach (IBuildDetail build in builds)
                {
                    IBuildDefinition definition = build.BuildDefinition;
                    if (definition != null)
                    {
                        string changeset = build.SourceGetVersion.Replace("C", string.Empty);  // changesets are prefixed with "C"
                        int gated = definition.ContinuousIntegrationType == ContinuousIntegrationType.Gated ? 1 : 0;
                        Console.WriteLine("{0}         {1}        {2}", changeset, gated, definition.Name);
                    }
                }
            }
        }
    }