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

by Ewald Hofman 2. October 2010 02:17

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
  16. Part 16: Specify the relative reference path 

 

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.

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:

Team Build | VSTS 2010

Comments

10/5/2010 4:22:38 AM #

roland flentge

NiceSmile

thanks

roland flentge Netherlands |

10/5/2010 11:23:32 AM #

tfs10

Thank you Ewald for the great posting.

Could you also please show how to display the duration of each sub-task in the custom build activity? Currently it only shows the duration of the whole build activity in my case. Should I use InformationNodeConverters.AddBuildMessage with a customized DataTime passing in?

Thank you.

tfs10 Canada |

10/9/2010 11:31:25 AM #

geoff

Excellent series. Dos anyone know how you might go about using AddExternalLink to create a link to a folder? when I try a Uri just to the folder I get could not be found error when I click the link.

geoff United States |

10/10/2010 10:54:17 PM #

Ewald Hofman

Did you add "file://" to the uri? For example file://c:\MyFolder or file://\\myserver\myshare

Ewald Hofman Netherlands |

10/21/2010 7:11:47 PM #

geoff

Yeah I tried that. I looks like it tries to open any link in the text editor. regardless of the file name or path.

geoff United States |

10/21/2010 4:20:43 AM #

Adi

Great Job. One Questions, how do you execute a batch file through an external Link? When i click the Link it just opens the File in a TextEditor in VS2010....

Adi Switzerland |

11/9/2010 5:32:38 AM #

trackback

Part 14: Execute a PowerShell script

Part 14: Execute a PowerShell script

Ewald Hofman |

11/10/2010 9:14:31 AM #

pingback

Pingback from blogs.like10.com

TechDays 2010 Presentations « Microsoft Team Foundation Server, SharePoint Server, .NET, and SQL Server

blogs.like10.com |

11/29/2010 10:01:39 AM #

Yuri

Another aproach would be:
            IActivityTracking currentTracking = context.GetExtension<IBuildLoggingExtension>().GetActivityTracking(context);
            currentTracking.Node.Children.AddBuildWarning("New message warning", DateTime.Now);
            currentTracking.Node.Children.AddBuildMessage("New message", BuildMessageImportance.High, DateTime.Now);
            currentTracking.Node.Children.AddBuildError("New error", DateTime.Now);

            currentTracking.Node.Children.AddExternalLink("My link", new Uri(@"http://www.ewaldhofman.nl"));
            currentTracking.Save();

By the way, this approach can be used for asynchronious activities.

Yuri Israel |

12/20/2010 11:50:34 AM #

Matthew Shin

Thanks for the tutorial. I would like to know if there is a way to display hyperlink not on the logs, but on the summary page of the build results.

Matthew Shin Canada |

5/31/2011 8:22:19 AM #

trackback

Ewald’s posts on TFS Build 2010

Ewald Hofman , an ALM MVP, has written a great series of blog posts on Team Build in Team Foundation Server 2010.  The 2010 release introduces Windows Workflow as the overall orchestrator of the build process.  Ewald walks you through quite a few topics related to this and the other new features.  Check it out! Part 1: Introduction Part 2: Add arguments and variables Part 3: Use more complex arguments Part 4: Create your own activity Part 5: Increase AssemblyVersion Part 6: Use custom type for an argument Part 7: How is the custom assembly found Part 8: Send information to the build log Part 9: Impersonate activities (run under other credentials) Part 10: Include Version Number in the Build Number Part 11: Speed up opening my build process template Part 12: How to debug my custom activities Part 13: Get control over the Build Output Part 14: Execute a PowerShell script Part 15: Fail a build based on the exit code of a console application Part 16: Specify the relative reference path Technorati Tags: tfs 2010 , team build , windows workflow

Buck Hodges |

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
487 comments
316 raters
1759221 visit (1044 per day)
19 users online

Recent comments

Comment RSS