【问题标题】:How do I get notified of a BuildDestroyedEvent如何获得 BuildDestroyedEvent 的通知
【发布时间】:2016-08-05 04:40:06
【问题描述】:

背景:

我有一个本地 TFS 2015 Update 1 服务器。在新的 TFS 构建样式中,通过网络共享 are not deleted when the build is deleted 从过期保留策略中删除构建。我们的设置不能使用基于服务器的 drop,我们必须使用网络共享 drop。

作为一种解决方法,我正在尝试编写一个服务,该服务将在构建过期并被删除时收到通知,然后它可以为我删除关联的网络共享。

问题:

我发现了.NET TFS client libraries,在Microsoft.TeamFoundationServer.Client NuGet 包中有一个Microsoft.TeamFoundation.Build.WebApi.Events.BuildDestroyedEvent 类,看起来完全符合我的需要。但是我不知道如何“订阅”该事件。

我使用 Microsoft.TeamFoundationServer.ExtendedClient API 找到了 a good tutorial,该 API 显示了对带有 Web 回调的 WorkItemChangedEvent 的订阅。但是,当我尝试使用 BuildDestroyedEvent 时,出现错误。

const string collectionUri = "https://tfs.example.com:8081/tfs/MyCollection";
static void Main(string[] args)
{
    using (TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(new Uri(collectionUri)))
    {
        tpc.Authenticate();
        tpc.EnsureAuthenticated();

        var eventService = tpc.GetService<IEventService>();

        DeliveryPreference del = new DeliveryPreference();
        del.Address = "http://srchamberlain.example.com/TestWebApp/api/destroyEventSink";
        del.Schedule = DeliverySchedule.Immediate;
        del.Type = DeliveryType.Soap;


        var id = eventService.SubscribeEvent("BuildDestroyedEvent", "", del);
        Console.WriteLine(id);
    }

    Console.ReadLine();
}

我在SubscribeEvent 行遇到的错误是

Microsoft.TeamFoundation.Framework.Client.TeamFoundationServiceException 未处理 错误代码=0 事件 ID=3000 H结果=-2146232832 IsRemoteException=true 日志异常=假 Message=事件类型 BuildDestroyedEvent 不存在。 报告异常=假 来源=Microsoft.TeamFoundation.Client 堆栈跟踪: 在 Microsoft.TeamFoundation.Client.Channels.TfsHttpClientBase.HandleReply(TfsClientOperation 操作,TfsMessage 消息,Object[]& 输出) 在 Microsoft.TeamFoundation.Client.Channels.TfsHttpClientBase.Invoke(TfsClientOperation 操作,Object[] 参数,TimeSpan 超时,Object[]& 输出) 在 Microsoft.TeamFoundation.Client.Channels.TfsHttpClientBase.Invoke(TfsClientOperation 操作,Object[] 参数,Object[]& 输出) 在 Microsoft.TeamFoundation.Client.Channels.TfsHttpClientBase.Invoke(TfsClientOperation 操作,Object[] 参数) 在 Microsoft.TeamFoundation.Framework.Client.EventWebService.SubscribeEvent(字符串 userId,字符串 eventType,字符串 filterExpression,DeliveryPreference 首选项,字符串 projectName) 在 Microsoft.TeamFoundation.Framework.Client.TeamFoundationEventService.SubscribeEvent(字符串 eventType、字符串 filterExpression、DeliveryPreference 首选项) 在 D:\Code\SandboxConsole\SandboxConsole\Program.cs:line 33 中的 SandboxConsole.Program.Main(String[] args) 在 System.AppDomain._nExecuteAssembly(RuntimeAssembly 程序集,字符串 [] 参数) 在 System.AppDomain.ExecuteAssembly(字符串 assemblyFile,证据 assemblySecurity,String [] args) 在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() 在 System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext,ContextCallback 回调,对象状态,布尔值 preserveSyncCtx) 在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback 回调,对象状态,布尔值 preserveSyncCtx) 在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext,ContextCallback 回调,对象状态) 在 System.Threading.ThreadHelper.ThreadStart() 内部异常: 演员="" H结果=-2146233087 朗=恩 Message=事件类型 BuildDestroyedEvent 不存在。 节点="" 角色="" 内部异常:

问题:

获取Microsoft.TeamFoundation.Build.WebApi.Events.BuildDestroyedEvent 触发通知的正确方法是什么?

【问题讨论】:

  • 您想要实时删除构建吗?如果没有,那么每天只需调用构建以检查它们是否被删除的日常工作就可以了。
  • 好主意,我想我会用它作为备用计划

标签: c# .net tfs tfsbuild tfs-2015


【解决方案1】:
  1. VSTS 的collectionUri 始终为https://xxx.visualstudio.com/DefaultCollection,无法识别其他格式。

  2. 这些教程都是针对本地 TFS,而不是 VSTS。由于 Event Subscriptions 是一个服务器端插件,但 VSTS 是托管的,它无法在服务器端运行 Subscription。 VSTS 不支持 .Net 事件订阅。

  3. VSTS 现在支持create a service hooks subscription,但支持的事件不包括 BuildDestroyedEvent。

支持的事件:

  • 构建完成
  • 代码推送(用于 Git 团队项目)
  • 拉取请求创建或更新(用于 Git 团队项目)
  • 已签入代码(TFVC 团队项目)
  • 创建、更新、删除、恢复或评论的工作项
  • 发布到团队会议室的消息

因此,您可以将 Harshil Lodhi 的建议作为一种解决方法。

【讨论】:

  • 对于第 1 点,我正在本地运行 TFS,我正在尝试连接到本地运行的 TFS 2015 Update 1(我们计划在本周末更新到 Update 2)。另外,我仍然想知道使用Microsoft.TeamFoundationServer.Client NuGet 包“订阅”Microsoft.TeamFoundation.Build.WebApi.Events 命名空间中的 任何 事件的方法是什么。
  • 我认为只有作为服务挂钩的一部分可用的事件才能订阅。您可以转到 TFS Web UI 和服务挂钩选项卡中的设置来查看事件。
  • 那些充当插件而不是外部服务的东西呢,他们没有更多的访问权限吗?我写的“服务”不需要是外部服务,我可以把它写成TFS的插件,只是不知道如何访问这些信息。
  • nkdagility.com/… 网站上查看所有可用活动的列表。没有 BuildDestroyedEvent。
  • 那么this in your TypeScript SDK for TFS 是什么意思?
猜你喜欢
  • 2012-07-10
  • 1970-01-01
  • 1970-01-01
  • 2020-12-16
  • 2011-03-28
  • 2010-11-27
  • 1970-01-01
  • 1970-01-01
  • 2012-06-19
相关资源
最近更新 更多