Welcome to Manicprogrammer Sign in | Join | Help

Who Broke The Build

By shops that run a rolling CI build versus a pure "build on every check-in" CI process I have often had it asked

"Is there a way to send an email to all the people that had a changeset as part of that build notifying if there is a build break?"

My answer is always- "Sure you can write a custom task for that. It sounds like a good exercise for you to learn how to create an MSBuild task"

Well I have put most of the code below. I haven't actually tested it so caveat emptor and I also haven't finished it. As it is missing the crucial piece of code that connects to the LDAP and gets the email for the users. This might take some playing with the user string in the collection to get it correct and then once that is done the ITaskItem needs to be created for each and added to the EmailAddresses array. But other than that this code probably works. :-) If you do grab it and finish it off and fix my omissions etc. you'll want to place this task in/after AfterGetChangesetsAndUpdateWorkItems otherwise I don't believe the task will have the data there to return. I told you I hadn't tested it.

At any rate, if you want to create a set of MSBuild Items consisting of email addresses of people who had a changeset in the broken build so that they can then be emailed via another task try out the following and let me know how it works. If I get to test it before you I will. It was really just for me to play around with some of the new Team Build OM.

 

   1: public class WhoBrokeTheBuild  : Microsoft.Build.Utilities.Task 
   2:    {
   3:        private TeamFoundationServer _tfs;
   4:  
   5:        [Output]
   6:        public ITaskItem[] EmailAddresses { get; set; }
   7:  
   8:        [Required]
   9:        public string TeamFoundationServerURL { get; set; }
  10:  
  11:        [Required]
  12:        public string BuildUri { get; set; }
  15:  
  17:        
  18:        public WhoBrokeTheBuild() { }
  19:  
  20:        public override bool Execute()
  21:        {
  22:            _tfs = TFSCommon.GetTFS(TeamFoundationServerURL);
  23:            IBuildDetail buildDetail = GetBuildDetail();
  24:            List<string> changesetOwners = GetChangesetOwners(buildDetail);
  25:            
  26:            //Now we should take the changesetOwners and look up their email
  27:            //in the LDAP creating ITaskItem to populate EmailAddresses
  28:            //but this hasn't been done yet
  29:            throw new System.NotImplementedException();   
  30:            
  31:            
  32:        }
  33:  
  34:        public IBuildDetail GetBuildDetail()
  35:        {
  36:            IBuildServer buildServer = (IBuildServer)_tfs.GetService(typeof(IBuildServer));
  37:            IBuildDetail buildDetail = buildServer.GetAllBuildDetails(new Uri(BuildUri));
  38:            return buildDetail;
  39:        }
  40:  
  41:        public List<string> GetChangesetOwners(IBuildDetail buildDetail)
  42:        {
  43:            List<string> changesetOwners = new List<string>();
  44:            
  45:            IBuildDefinition buildDefinition = buildDetail.BuildDefinition;
  46:            if (buildDefinition.LastGoodBuildUri != buildDefinition.LastBuildUri)
  47:            {
  48:                return changesetOwners;
  49:            }
  50:  
  51:            List<IChangesetSummary> assocChangesets = InformationNodeConverters.GetAssociatedChangesets(buildDetail);
  52:            foreach (IChangesetSummary csSum in assocChangesets)
  53:            {
  54:                if (!(changesetOwners.Contains(csSum.CheckedInBy)))
  55:                {
  56:                    changesetOwners.Add(csSum.CheckedInBy);
  57:  
  58:                }
  59:            }
  60:  
  61:            return changesetOwners;
  62:        }
  63:  
  64:    }
Published Wednesday, December 19, 2007 7:06 AM by michaelruminer
Filed under ,

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

Wednesday, December 19, 2007 8:03 AM by willeke

# re: Who Broke The Build

That's very much full of maybe ;)

How busy ARE you these days ;)

Wednesday, December 19, 2007 8:27 AM by Michael Ruminer

# re: Who Broke The Build

Eric,

I owe you at least 1 email and likely a conversation or two or three. :-) I'm actually really busy but also not so busy. If that makes any sense. You know how it is starting a new gig/employer and trying to get up to speed on everything and keep forward momentum at the same time. I am not working long days as I am used to but I am exhausted at the end from the pure volume I am trying to absorb. I can see that exhaustion beginning to diminish as I get a grasp on things so hopefully I'll get to cirlce back around to this code before I get blasted for how much it might not work. *LOL* There's a 4 day weekend coming up so I hope to get a few more things posted and a 'verified' version of this will be one. That's why I decided to finally just post the small bit of code I had done as it was doing no one any good on my computer. And I already have piles of stuff I never get posted because I start the post and don't complete it. Even this post suffered from terseness. For instance I didn't explain why I compare

buildDefinition.LastGoodBuildUri != buildDefinition.LastBuildUri

If I had commented or written tests you'd know  but instead if it's not clear to anyone I'll end up explaining the reason and then probably find a fallacy in the logic.

Look forward to talking to you soon more directly!

Wednesday, December 19, 2007 8:44 AM by Gabriel Lozano-Moran

# re: Who Broke The Build

On a side-note what do you use to embed source code with syntax highlighting in your blog posts?

Wednesday, December 19, 2007 10:22 AM by Michael Ruminer

# re: Who Broke The Build

This is the plug-in I used. I like it. It has a few quirks but I see that it is now on CodePlex so those can be fixed more readily.

http://lvildosola.blogspot.com/2007/02/code-snippet-plugin-for-windows-live.html

I really like it so far.

Thursday, December 20, 2007 8:38 AM by michaelruminer

# re: Who Broke The Build

That's the same one that you see above.

Friday, December 21, 2007 9:42 AM by Team System News

# VSTS Links - 12/21/2007

Maor David on Custom Build Numbers in Team Build. GertD on Cleaning up DesignDB Leftovers and Is DesignDB...


Enter the text you see in the image:

Leave a Comment

(required) 
required 
(required)