Click here to Skip to main content
Click here to Skip to main content

TFS API–Release Notes From TFS Builds

, 25 Dec 2011
Rate this:
Please Sign up or sign in to vote.
  Agile taught us to release early and release often, Agile also taught us to get the end user involved more frequently and directly. Goes without saying that release notes are an important part of any release. But what you don’t want to be doing is manually putting together the release notes with

 

Agile taught us to release early and release often, Agile also taught us to get the end user involved more frequently and directly. Goes without saying that release notes are an important part of any release. But what you don’t want to be doing is manually putting together the release notes with each frequent release you do. TFS lets you manage the application lifecycle with great ease & minimal administrative overhead, if your team is already checking in the code against work items and if you are using the TFS build infrastructure, good news is you already have all the raw material for your release notes stored in the TFS repository, in this blog post I’ll show you how to use the TFS API to generate the release notes from the Team builds.

image  So… How does it work?

  •   => Click connect to get all Build Definitions for a Team Project
  •   => Filter by excluding Disabled Build Definitions, or select the no.
  •        of builds to return per build definition, or exclude failed,
  •        partially successful, stopped and in progress builds.
  •   => Click ‘Generate Release Notes’ to generate the release
  •        notes, you can also export the results to PDF 

 

     image

 

Let’s get started, follow the steps below or download a working solution & an executable from here.

1. What you need…

To be able to extract the work item details from the build, you need to ensure,

  • Developers check in code against work items – Download and Install TFS Power tools and enable check in policy to enforce check ins against work items.
  • Enable the association of work items with change sets – If you are using the default template that ships with TFS 2010, edit the build definition and under the Process tab in the Advanced settings you will notice the option ‘Associate Change sets and Work Items’ set this to true.

        image

2. TFS API – Programmatically get Work Items, Change sets, etc. from Team Builds

  • 1. Let’s start by connecting to TFS programmatically using the API
<span style="color: blue">   private </span><span style="color: #2b91af">TfsTeamProjectCollection </span>_tfs;
   <span style="color: blue">private string </span>_selectedTeamProject;
   <span style="color: blue">private </span><span style="color: #2b91af">IBuildServer </span>_bs;
   <span style="color: blue">private </span><span style="color: #2b91af">WorkItemStore </span>_wis;

   <span style="color: green">// Connect to TFS and pick team project
   </span><span style="color: blue">private void </span>ConnectToTfsAndPickAProject()
   {
       <span style="color: #2b91af">TeamProjectPicker </span>tfsPP = <span style="color: blue">new </span><span style="color: #2b91af">TeamProjectPicker</span>(<span style="color: #2b91af">TeamProjectPickerMode</span>.SingleProject, <span style="color: blue">false</span>);
       tfsPP.ShowDialog();
       <span style="color: blue">this</span>._tfs = tfsPP.SelectedTeamProjectCollection;
       <span style="color: blue">this</span>._selectedTeamProject = tfsPP.SelectedProjects[0].Name;
   }
  • 2. Get all Build Definitions for the selected Team Project programmatically
<span style="color: green">    // Get All Build Definitions for the selected Team Project
    </span><span style="color: blue">private </span><span style="color: #2b91af">IBuildDefinition</span>[] GetAllBuildDefinitionsFromTheTeamProject()
    {
        _bs = _tfs.GetService<<span style="color: #2b91af">IBuildServer</span>>
  • 3. Get All Builds in the build definition for specific build Definition specifications programmatically, this helps you narrow down the search and get the selected few filtered results, like in the snippet below, we specify the maximum number of builds to return, what build quality builds to return, etc.
<span style="color: green">     // Get All Builds for the selected build definition 
     </span><span style="color: blue">private void </span>cmbBuilds_SelectedIndexChanged(<span style="color: blue">object </span>sender, <span style="color: #2b91af">EventArgs </span>e)
     {
         <span style="color: blue">var </span>def = (((<span style="color: #2b91af">ComboBox</span>)sender).SelectedItem) <span style="color: blue">as </span><span style="color: #2b91af">IBuildDefinition</span>;

         <span style="color: blue">var </span>def = _bs.CreateBuildDetailSpec(_selectedTeamProject);
         <span style="color: blue">int </span>noRequeted; <span style="color: green">// set to 1 in case no value passed
         </span>def.MaxBuildsPerDefinition = (<span style="color: blue">int</span>.TryParse(txtNoOfBuilds.Text.ToString(), <span style="color: blue">out </span>noRequeted)) ? noRequeted : 1;
         def.QueryOrder = <span style="color: #2b91af">BuildQueryOrder</span>.FinishTimeDescending;
         def.DefinitionSpec.Name = def.Name;
         def.Status = chkOnlySuccessful.Checked ? <span style="color: #2b91af">BuildStatus</span>.Succeeded : <span style="color: #2b91af">BuildStatus</span>.All;
         <span style="color: blue">var </span>builds = _bs.QueryBuilds(def).Builds;

         lstBuilds.Items.Clear();
         <span style="color: blue">foreach </span>(<span style="color: blue">var </span>build <span style="color: blue">in </span>builds)
         {
            lstBuilds.Items.Add(build);
            lstBuilds.DisplayMember = <span style="color: #a31515">"BuildNumber"</span>;
         }
         lstBuilds.SelectionMode = <span style="color: #2b91af">SelectionMode</span>.MultiExtended;
     }
  • 4. Get Associated Work Items for the selected build. You can also get the Associated Change sets, Build errors, Build Warnings, Work flow details, Changeset Ids, Configuration summaries, Opened work item ids, etc, check for more details for InformationNodeConverters. Notice in the snippet below that I am excluding a work item if it has already been added to the release notes as part of the previous selected build.
<span style="color: green">   // Data I want to display on the report
   </span><span style="color: blue">public class </span><span style="color: #2b91af">ReleaseNote
   </span>{
        <span style="color: blue">public string </span>BuildNumber { <span style="color: blue">get</span>; <span style="color: blue">set</span>; }
        <span style="color: blue">public int </span>WorkItemId { <span style="color: blue">get</span>; <span style="color: blue">set</span>; }
        <span style="color: blue">public string </span>WorkItemTitle { <span style="color: blue">get</span>; <span style="color: blue">set</span>; }
        <span style="color: blue">public string </span>QcRef { <span style="color: blue">get</span>; <span style="color: blue">set</span>; }
   }

    <span style="color: green">// Get the work item details off the selected Builds
    </span><span style="color: blue">private void </span>btnReleaseNotes_Click(<span style="color: blue">object </span>sender, <span style="color: #2b91af">EventArgs </span>e)
    {
            <span style="color: blue">var </span>workItemIds = <span style="color: blue">new </span><span style="color: #2b91af">List</span><<span style="color: blue">int</span>>

 

Next… Create a Report using the Report Wizard and associate it to the Release Note Binding Source. Download a working solution and executable from here.

3. Review & Next Steps…

You can use the same logic with in a custom activity to churn out the release note details in the format you want in the build output, or use the code in a web application , host it in your network and easily let the team query the release notes as and when they need to, or host this in the cloud so the vendors outside the network can easily access the release notes as well, you could also convert this in to a VS extension, right click the build definition and you have the option to generate the release notes. You can also extend the logic further and include more functionality. Happy to hear your feedback! If you have any recommendations or questions, feel free to leave a comment. Thank you for taking the time out and reading this blog post. If you enjoyed the post, remember to subscribe to http://feeds.feedburner.com/TarunArora.

Check out the other posts on cool tools using TFS API. In love

 

Share this post :

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Tarun_Arora
Software Developer (Senior) Avanade
United Kingdom United Kingdom
Solution Developer - C# .NET, ALM
 
Tarun Arora is a Microsoft Certified professional developer for Enterprise Applications. He has over 5 years of experience developing 'Energy Trading & Risk Management' solutions using Microsoft Technologies. Tarun has great passion for technology and travel (not necessarily in the same order)!
Follow on   Twitter

Comments and Discussions

 
Questioncan't get working PinmemberDerek Mahlitz8-Nov-12 7:44 
GeneralMy vote of 5 PinmemberSledgeHammer0128-Dec-11 9:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 26 Dec 2011
Article Copyright 2011 by Tarun_Arora
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid