Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 207401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:43:57+00:00 2026-05-11T17:43:57+00:00

We are using continuous integration as part of our build automation. For every check

  • 0

We are using continuous integration as part of our build automation. For every check in, the tfs build server builds the project and deploys to our web servers on success.

When the build fails, it automatically creates a new Bug with the details of the build failure.

Due to CI and the activity on the server, this might result in 10 or 20 failure work items before the build starts succeeding again.

So, I have two options. I’d like to either have the build process see if an open work item already exists for a build failure and just add details to that; OR, I’d like the build server to close all of the build failure items automatically when it starts working again.

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T17:43:57+00:00Added an answer on May 11, 2026 at 5:43 pm

    You can create a MSBuild Task to do either of these options. Here is a similar piece of code I use to get you started but since I don’t know the details of your work item or process you will have to change it.

    This code takes all of the work items associated with a build and updates their status.

    If you select your first option you can just change the UpdateWorkItemStatus method and update any existing WIs. For the Second method you will need to do a bit more work as you need to look up the prior build rather than take it as a input.

    using System;
    using System.Collections.Generic;
    using System.Text;
    using Microsoft.Build.Utilities;
    using Microsoft.TeamFoundation.Client;
    using Microsoft.TeamFoundation.WorkItemTracking.Client;
    using Microsoft.Build.Framework;
    using Microsoft.TeamFoundation.Build;
    using Microsoft.TeamFoundation.Build.Client;
    
    namespace Nowcom.TeamBuild.Tasks
    {
        public class UpdateWorkItemState: Task
        {
            private IBuildDetail _Build;
    
            private void test()
            {
                TeamFoundationServerUrl = "Teamserver";
                BuildUri = "vstfs:///Build/Build/1741";
                Execute();
            }
    
            public override bool Execute()
            {
                bool result = true;
    
                try
                {
                    TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(TeamFoundationServerUrl, new UICredentialsProvider());
                    tfs.EnsureAuthenticated();
    
                    WorkItemStore store = (WorkItemStore)tfs.GetService(typeof(WorkItemStore));
                    IBuildServer buildServer = (IBuildServer)tfs.GetService(typeof(IBuildServer));
                    _Build = buildServer.GetAllBuildDetails(new Uri(BuildUri));
                    //add build step
                    IBuildStep buildStep = InformationNodeConverters.AddBuildStep(_Build, "UpdateWorkItemStatus", "Updating Work Item Status");
    
    
                    try
                    {
                        Log.LogMessageFromText(string.Format("Build Number: {0}", _Build.BuildNumber), MessageImportance.Normal);
    
                        List<IWorkItemSummary> assocWorkItems = InformationNodeConverters.GetAssociatedWorkItems(_Build);
    
                            // update work item status 
                            UpdateWorkItemStatus(store, assocWorkItems, "Open", "Resolved");
    
                        SaveWorkItems(store, assocWorkItems);
                    }
                    catch (Exception)
                    {
                        UpdateBuildStep(buildStep, false);
                        throw;
                    }
    
                    UpdateBuildStep(buildStep, result);
                 }
                catch (Exception e)
                {
                    result = false;
    
                    BuildErrorEventArgs eventArgs;
                    eventArgs = new BuildErrorEventArgs("", "", BuildEngine.ProjectFileOfTaskNode, BuildEngine.LineNumberOfTaskNode, BuildEngine.ColumnNumberOfTaskNode, 0, 0, string.Format("UpdateWorkItemState failed: {0}", e.Message), "", "");
    
                    BuildEngine.LogErrorEvent(eventArgs);
    
                    throw;
                }
    
                return result;
            }
    
            private static void SaveWorkItems(WorkItemStore store, List<IWorkItemSummary> assocWorkItems)
            {
                foreach (IWorkItemSummary w in assocWorkItems)
                {
                    WorkItem wi = store.GetWorkItem(w.WorkItemId);
    
                    if (wi.IsDirty)
                    {
                        wi.Save();
                    }
                }
            }
    
            // check in this routine if the workitem is a bug created by your CI process. Check by title or assigned to or description depending on your process.
            private void UpdateWorkItemStatus(WorkItemStore store, List<IWorkItemSummary> assocWorkItems, string oldState, string newState)
            {
                foreach (IWorkItemSummary w in assocWorkItems)
                {
                    Log.LogMessageFromText(string.Format("Updating Workitem Id {0}", w.WorkItemId), MessageImportance.Normal);
                    WorkItem wi = store.GetWorkItem(w.WorkItemId);
                    if (wi.Fields.Contains("Microsoft.VSTS.Build.IntegrationBuild") && wi.State != "Resolved")
                    {
                        wi.Fields["Microsoft.VSTS.Build.IntegrationBuild"].Value =_Build.BuildNumber;
                    }
                    if (wi.State == oldState)
                    {
                        wi.State = newState;
                        foreach (Field field in wi.Fields)
                        {
                            if (!field.IsValid)
                            {
                                break;
                            }
                        }
                    }
    
                    if (wi.IsDirty)
                    {
                        wi.Save();
                    }
                }
            }
    
            private void UpdateBuildStep(IBuildStep step, bool result)
            {
                step.Status = result ? BuildStepStatus.Succeeded : BuildStepStatus.Failed;
                step.FinishTime = DateTime.Now;
                step.Save();
            }
    
            [Required]
            public string BuildUri { get; set; }
    
            [Required]
            public string TeamFoundationServerUrl {get; set;}
        }
    }
    
    
    
     < UpdateWorkItemState
    TeamFoundationServerUrl="$(TeamFoundationServerUrl)"
    BuildUri="$(BuildUri)"
    ContinueOnError="false"/>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As part of our Continuous Integration builds, I'd like the build to fail if
In using our TeamCity Continuous Integration server we have uncovered some issues that we
We are using Hudson for our Continuous Integration server and it's great. We have
Has anyone used Hudson as a Continuous-Integration server for a C++ project using UnitTest++
We have been using TeamBuild and test for our continuous integration build for about
I am using Ivy as part of my continuous integration build system, but I
So, we're using continuous integration in our current Team Foundation Server 2010 setup, and
We are using TeamCity v4 and NAnt for continuous integration builds on a server
I am trying to get SpecUnit to run in a continuous integration build using
For the past 2 years-(ish) I've been using Maven2 for my build/continuous integration solution.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.