gpt4 book ai didi

tfsbuild - TFS 2010 API,确定构建在哪个构建服务器上运行。

转载 作者:行者123 更新时间:2023-12-04 11:58:03 25 4
gpt4 key购买 nike

抱歉,这几乎肯定是 this question 的副本但由于那个问题没有得到答复,我将再试一次。

我正在尝试构建一个工具,该工具将允许我查看在 TFS 上排队或运行的所有构建。

要求之一是能够查看构建运行在哪个构建服务器上。 IQueuedBuildsView 中的所有“BuildAgent”属性和方法都已弃用并抛出未实现的异常。有很多查询代理的方法,但是在您可以这样做之前,您需要代理 uri 或名称,我觉得我处于鸡和蛋的境地。

有谁知道如何为正在运行的构建找到构建服务器名称?我下面的代码片段可能会有所帮助。

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Net;
using System.Text;
using Microsoft.TeamFoundation.Server;
using Microsoft.TeamFoundation.Build.Client;
using Microsoft.TeamFoundation.VersionControl.Client;
using Microsoft.TeamFoundation.Framework.Client;
using Microsoft.TeamFoundation.Framework.Common;
using Microsoft.TeamFoundation.Client;


namespace TeamFoundationServerTools
{
public static class TeamBuildData
{

public static void Main()
{

Uri teamFoundationServerUri = new Uri("http://tfs:8080/tfs");
Uri teamFoudationServerProjectCollectionUri = new Uri("http://tfs:8080/tfs/collection");
string teamFoundationServerName = "tfs";
string teamFoundationServerProjectCollectionName = string.Empty;
string teamFoundationServerProjectName = string.Empty;

try
{

Dictionary<string, Uri> collections = new Dictionary<string, Uri>();

if (string.IsNullOrEmpty(teamFoundationServerProjectCollectionName))
{
DetermineCollections(teamFoundationServerUri, collections);
}
else
{
collections.Add(teamFoundationServerName, teamFoudationServerProjectCollectionUri);
}

QueryCollections(teamFoundationServerName, teamFoundationServerProjectName, collections);

}
catch (Exception ex)
{
Console.Write(ex.ToString());
}
}

/// <summary>
/// Queries the Team project collection for team builds
/// </summary>
/// <param name="teamFoundationServerName">the name of the TFS server</param>
/// <param name="teamFoundationServerProjectName">the name of the Team Project</param>
/// <param name="collections">the Team Project Collections to be queried</param>
private static void QueryCollections(string teamFoundationServerName, string teamFoundationServerProjectName, Dictionary<string, Uri> collections)
{
foreach (KeyValuePair<string, Uri> collection in collections)
{
// connect to the collection
using (TfsTeamProjectCollection teamProjectCollection = new TfsTeamProjectCollection(collection.Value, CredentialCache.DefaultCredentials))
{
Console.WriteLine(teamProjectCollection.Name);

IBuildServer buildServer = (IBuildServer)teamProjectCollection.GetService(typeof(IBuildServer));

// get ICommonStructureService (later to be used to list all team projects)
ICommonStructureService commonStructureService = (ICommonStructureService)teamProjectCollection.GetService(typeof(ICommonStructureService));

// I need to list all the TFS Team Projects that exist on a server
ProjectInfo[] allTeamProjects;

if (!String.IsNullOrEmpty(teamFoundationServerProjectName))
{
allTeamProjects = new ProjectInfo[1];
allTeamProjects[0] = new ProjectInfo();
allTeamProjects[0] = commonStructureService.GetProjectFromName(teamFoundationServerProjectName);
}
else
{
allTeamProjects = commonStructureService.ListProjects();
}

// iterate thru the team project list
foreach (ProjectInfo teamProjectInfo in allTeamProjects)
{
Console.WriteLine(teamProjectInfo.Name);

// skip this team project if it is not WellFormed.
if (teamProjectInfo.Status != ProjectState.WellFormed)
{
continue;
}

IQueuedBuildsView queuedBuildsView = buildServer.CreateQueuedBuildsView(teamProjectInfo.Name);
queuedBuildsView.StatusFilter = QueueStatus.Queued | QueueStatus.InProgress | QueueStatus.Postponed;

queuedBuildsView.QueryOptions = QueryOptions.All;

queuedBuildsView.Refresh(false);
foreach (IQueuedBuild queuedBuild in queuedBuildsView.QueuedBuilds)
{
Console.WriteLine(queuedBuild.BuildDefinition.Name);
Console.WriteLine(queuedBuild.BuildController.Name);
Console.WriteLine(queuedBuild);
Console.WriteLine(queuedBuild.Status);
Console.WriteLine(queuedBuild.RequestedBy);
Console.WriteLine(queuedBuild.QueuePosition);
Console.WriteLine(queuedBuild.QueueTime);
Console.WriteLine(queuedBuild.Priority);
Console.WriteLine();

if (queuedBuild.Status == QueueStatus.InProgress)
{


}

Console.WriteLine("***********************");

}
}
}
}

Console.ReadLine();
}

/// <summary>
/// Determins the team project collections for a given TFS instance
/// </summary>
/// <param name="teamFoundationServerUri">the uri of the Team Foundation Server</param>
/// <param name="collections">a dictionary of collections to be added to</param>
private static void DetermineCollections(Uri teamFoundationServerUri, Dictionary<string, Uri> collections)
{
// get a list of Team Project Collections and their URI's
using (TfsConfigurationServer tfsConfigurationServer = new TfsConfigurationServer(teamFoundationServerUri))
{
CatalogNode configurationServerNode = tfsConfigurationServer.CatalogNode;

// Query the children of the configuration server node for all of the team project collection nodes
ReadOnlyCollection<CatalogNode> tpcNodes = configurationServerNode.QueryChildren(
new Guid[] { CatalogResourceTypes.ProjectCollection },
false,
CatalogQueryOptions.None);

foreach (CatalogNode tpcNode in tpcNodes)
{
ServiceDefinition tpcServiceDefinition = tpcNode.Resource.ServiceReferences["Location"];

ILocationService configLocationService = tfsConfigurationServer.GetService<ILocationService>();
Uri tpcUri = new Uri(configLocationService.LocationForCurrentConnection(tpcServiceDefinition));

collections.Add(tpcNode.Resource.DisplayName, tpcUri);
}
}
}
}
}

最佳答案

我创建了一个 LinqPad脚本来做到这一点。通过查询 Controller 上的所有代理,您可以看到针对每个代理运行的构建。我根据自己的喜好在脚本中添加了一些额外的东西。

TFS Build Agents在我的 SkyDrive 上

关于tfsbuild - TFS 2010 API,确定构建在哪个构建服务器上运行。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8748643/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com