locked
Getting the latest build in TFS with C# RRS feed

  • Question

  • Hi there, 

    I have code which determines if the latest build for a certain build definition in TFS was successful. It works fien on my local machine but when rolled out I get the following error:

    TF215024: The build path \TestDefinition Service must specify an item name. 

    The code is:

    var buildService = (IBuildServer)_TfsTeamProjectCollection.GetService(typeof(IBuildServer));
    {
    	if (buildService != null)
    	{
    		IBuildDetailSpec buildDetailSpec = buildService.CreateBuildDetailSpec(Config.TFSProject, buildDefinition);
    		{
    			buildDetailSpec.MaxBuildsPerDefinition = 1;
    			buildDetailSpec.QueryOrder = BuildQueryOrder.FinishTimeDescending;
    		}
    		
    		IBuildQueryResult buildQueryResults = buildService.QueryBuilds(buildDetailSpec);
    		{
    			if (buildQueryResults.Builds.Length == 1)
    			{
    				return (buildQueryResults.Builds[0].Status == BuildStatus.Succeeded);
    			}
    		}
    	}
    }
    

    I don't understand why this works locally but errors when rolled out. I authenticate to TFS with a web user account and it works fine with creating/viewing work items.

     

    Cheers

    • Moved by Leo Liu - MSFT Thursday, May 5, 2011 7:59 AM Moved for better support. (From:Visual C# General)
    Wednesday, May 4, 2011 1:47 AM

Answers

  • Hi Cheers,

     

    Thanks for your post.

     

    Please try to use the following codes snippet to get IBuildServer on other client:

     

                TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(new Uri("url"));
                tfs.Authenticate();
                IBuildServer tfsBuildServer = tfs.GetService<IBuildServer>();


    John Qiao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, May 5, 2011 8:14 AM
    Moderator

All replies

  • I am moving your thread into the Team Foundation Server - Build Automation Forum for specialized support. Thanks.
    Leo Liu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, May 5, 2011 7:58 AM
  • Hi Cheers,

     

    Thanks for your post.

     

    Please try to use the following codes snippet to get IBuildServer on other client:

     

                TfsTeamProjectCollection tfs = new TfsTeamProjectCollection(new Uri("url"));
                tfs.Authenticate();
                IBuildServer tfsBuildServer = tfs.GetService<IBuildServer>();


    John Qiao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, May 5, 2011 8:14 AM
    Moderator
  • Hi Cheers,

     

    Has this issue been resolved?     


    John Qiao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, May 6, 2011 8:59 AM
    Moderator
  • I have the same problem and the answer by John did not help.

     

    The following code used to work (I think prior to SP1):

     

     

    IBuildDetail foundBuildDetail = null;
    
                // Get the specified Team Project Collection.
                var tpc = new TfsTeamProjectCollection(new Uri("url"));
                tpc.Authenticate();
                // Get the build server.
                var buildServer = tpc.GetService<IBuildServer>();
                if (buildServer != null)
                {
                    // Get list of builds.
                    foundBuildDetail = buildServer.GetBuild(buildServer.CreateBuildDefinitionSpec(teamProjectName, buildDefinition), buildNumber, null, QueryOptions.None);
                }
    

    Any idea how this can be fixed?

     


    Monday, October 3, 2011 3:48 PM
  • I found what my problem was. In some cases, the build definition given to BuildDefinitionSpec was empty. In those cases, a '*' need to be given in order  to match any build definition.


    Monday, October 3, 2011 4:04 PM
  • Please use the below code,

                            

    var tfsUri = new Uri(ConfigurationManager.AppSettings["Tfs.WebSite"] + ConfigurationManager.AppSettings["Tfs.CollectionName"]);
    var userCreds = new NetworkCredential(ConfigurationManager.AppSettings["Tfs.User"], ConfigurationManager.AppSettings["Tfs.Password"], ConfigurationManager.AppSettings["Tfs.Domain"]);

    private DataTable RenderTfsBuildDefinitions(string projectname, string projectid)
            {
                var dt = new DataTable();
                dt.Clear();
                dt.Columns.Add("Id");
                dt.Columns.Add("Name");

                var tpc = new TfsTeamProjectCollection(this.tfsUri, this.userCreds);
                tpc.EnsureAuthenticated();
                var buildService = (IBuildServer)tpc.GetService(typeof(IBuildServer));

                // get all build spec, you can add any team project name or build definition or wildcards
                var buildDetailSpec = buildService.CreateBuildDetailSpec(projectname, "*");
                {
                    buildDetailSpec.MaxBuildsPerDefinition = 1;
                    buildDetailSpec.QueryOrder = BuildQueryOrder.FinishTimeDescending;
                }

                // Get all gugued build now from specific team project collection
                var buildQueryResults = buildService.QueryBuilds(buildDetailSpec);

                // Filter the information the get the data you want to view it in grid
                foreach (var qb in buildQueryResults.Builds)
                {
                    if (qb.BuildDefinition != null && !string.IsNullOrEmpty(qb.BuildDefinition.Name))
                    {
                        var definitionName = qb.BuildDefinition.Name;
                        var definitionId = qb.BuildDefinition.Id;
                        dt.Rows.Add(definitionId, definitionName);
                    }
                }

                return dt;
            }

    • Proposed as answer by Biswadas2 Friday, November 20, 2015 8:42 AM
    Friday, November 20, 2015 8:42 AM