Customize Team Build 2010 – Part 13: Get control over the Build Output

by Ewald Hofman 12. December 2010 22:57

In the series the following parts have been published

  1. Part 1: Introduction
  2. Part 2: Add arguments and variables
  3. Part 3: Use more complex arguments
  4. Part 4: Create your own activity
  5. Part 5: Increase AssemblyVersion
  6. Part 6: Use custom type for an argument
  7. Part 7: How is the custom assembly found
  8. Part 8: Send information to the build log
  9. Part 9: Impersonate activities (run under other credentials)
  10. Part 10: Include Version Number in the Build Number
  11. Part 11: Speed up opening my build process template
  12. Part 12: How to debug my custom activities
  13. Part 13: Get control over the Build Output
  14. Part 14: Execute a PowerShell script
  15. Part 15: Fail a build based on the exit code of a console application

In the part 8, I have explained how you can add informational messages, warnings or errors to the build output. If you want to integrate with other lines of text to the build output, you need to do more. This post will show you how you can add extra steps, additional information and hyperlinks to the build output.

UPDATE 13-12-2010: Thanks to Jason Pricket, it is now also possible to not show every activity in the build log. This is really useful when you are doing for-loops in your template. To see how you can do that, check out Jason's blog: http://blogs.msdn.com/b/jpricket/archive/2010/12/09/tfs-2010-making-your-build-log-less-noisy.aspx

Add an hyperlink to the end of the build output

Lets start with a simple example of how you can adjust the build output. In this case we are going to add at the end of the build output an hyperlink where a user can click on to for example start the deployment to the test environment.

In part 4 you can find information how you can create a custom activity

To add information to the build output, you need the BuildDetail. This value is a variable in your xaml and is thus easily transferable to you custom activity. Besides the BuildDetail the user has also to specify the text and the url that has to be added to the end of the build output.

The following code segment shows you how you can achieve this.

    [BuildActivity(HostEnvironmentOption.All)]
    public sealed class AddHyperlinkToBuildOutput : CodeActivity
    {
        [RequiredArgument]
        public InArgument<IBuildDetail> BuildDetail { get; set; }
 
        [RequiredArgument]
        public InArgument<string> DisplayText { get; set; }
 
        [RequiredArgument]
        public InArgument<string> Url { get; set; }
 
        protected override void Execute(CodeActivityContext context)
        {
            // Obtain the runtime value of the input arguments           
            IBuildDetail buildDetail = context.GetValue(this.BuildDetail);
            string displayText = context.GetValue(this.DisplayText);
            string url = context.GetValue(this.Url);

            // Add the hyperlink
            buildDetail.Information.AddExternalLink(displayText, new Uri(url));
            buildDetail.Information.Save();
        }
    }
If you add this activity to somewhere in your build process template (within the scope Run on Agent), you will get the following build output
image 

Add an line of text to the build output

The next challenge is to add this kind of output not only to the end of the build output but at the step that is currently executing. To be able to do this, you need the current node in the build output. The following code shows you how you can achieve this.

First you need to get the current activity tracking, which you can get with the following line of code

            IActivityTracking currentTracking = context.GetExtension<IBuildLoggingExtension>().GetActivityTracking(context);

Then you can create a new node and set its type to Activity Tracking Node (so copy it from the current node) and do nice things with the node.

            IBuildInformationNode childNode = currentTracking.Node.Children.CreateNode();
            childNode.Type = currentTracking.Node.Type;
            childNode.Fields.Add("DisplayText", "This text is displayed.");

You can also add a build step to display progress

            IBuildStep buildStep = childNode.Children.AddBuildStep("Custom Build Step", "This is my custom build step");
            buildStep.FinishTime = DateTime.Now.AddSeconds(10);
            buildStep.Status = BuildStepStatus.Succeeded;
Or you can add an hyperlink to the node
            childNode.Children.AddExternalLink("My link", new Uri(http://www.ewaldhofman.nl));
When you combine this together you get the following result in the build output

image 


You can download the full solution at BuildProcess.zip. It will include the sources of every part and will continue to evolve.

Tags:

Comments

4/7/2011 1:17:41 AM #

pingback

Pingback from ewaldhofman.nl

Ewald Hofman | Part 15: Fail a build based on the exit code of a console application

ewaldhofman.nl |

5/31/2011 8:23:00 AM #

pingback

Pingback from blogs.msdn.com

MSDN Blogs

blogs.msdn.com |

10/23/2013 10:54:21 AM #

pingback

Pingback from ask.techwikihow.com

c# – TFS 2010: How to create BuildDetail Links that can be displayed in a webbrowser? | Ask TechwikiHow

ask.techwikihow.com |

3/19/2014 10:55:51 PM #

pingback

Pingback from blogs.microsoft.co.il

Obtaining Build Stop in Long-Run Activity | Roy Rosenberg

blogs.microsoft.co.il |

Comments are closed

Powered by BlogEngine.NET 1.6.1.0
Theme by Mads Kristensen


ClusterMap

Statistics

Statistics created at 09 Sep 2009

121 posts
488 comments
323 raters
1854529 visit (1043 per day)
23 users online

Recent comments

Comment RSS