如何收到BuildDestroyedEvent的通知

时间:2016-04-13 20:51:08

标签: c# .net tfs tfsbuild tfs2015

背景:

我有一个内部部署TFS 2015 Update 1服务器。在新的TFS构建样式中,通过网络共享are not deleted when the build is deleted构建从即将到期的保留策略中删除的内容。我们的设置无法使用基于服务器的丢弃,我们必须使用网络共享丢弃。

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

问题:

我发现了.NET TFS client libraries,在Microsoft.TeamFoundationServer.Client NuGet包中有一个Microsoft.TeamFoundation.Build.WebApi.Events.BuildDestroyedEvent类,看起来就像我需要的那样。但是我无法弄清楚如何订阅"那件事。

我使用a good tutorial API找到了Microsoft.TeamFoundationServer.ExtendedClient,该API显示了对带有网络回调的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 was unhandled
  ErrorCode=0
  EventId=3000
  HResult=-2146232832
  IsRemoteException=true
  LogException=false
  Message=Event type BuildDestroyedEvent does not exist.
  ReportException=false
  Source=Microsoft.TeamFoundation.Client
  StackTrace:
       at Microsoft.TeamFoundation.Client.Channels.TfsHttpClientBase.HandleReply(TfsClientOperation operation, TfsMessage message, Object[]& outputs)
       at Microsoft.TeamFoundation.Client.Channels.TfsHttpClientBase.Invoke(TfsClientOperation operation, Object[] parameters, TimeSpan timeout, Object[]& outputs)
       at Microsoft.TeamFoundation.Client.Channels.TfsHttpClientBase.Invoke(TfsClientOperation operation, Object[] parameters, Object[]& outputs)
       at Microsoft.TeamFoundation.Client.Channels.TfsHttpClientBase.Invoke(TfsClientOperation operation, Object[] parameters)
       at Microsoft.TeamFoundation.Framework.Client.EventWebService.SubscribeEvent(String userId, String eventType, String filterExpression, DeliveryPreference preferences, String projectName)
       at Microsoft.TeamFoundation.Framework.Client.TeamFoundationEventService.SubscribeEvent(String eventType, String filterExpression, DeliveryPreference preferences)
       at SandboxConsole.Program.Main(String[] args) in D:\Code\SandboxConsole\SandboxConsole\Program.cs:line 33
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 
       Actor=""
       HResult=-2146233087
       Lang=en
       Message=Event type BuildDestroyedEvent does not exist.
       Node=""
       Role=""
       InnerException: 

问题:

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

1 个答案:

答案 0 :(得分:0)

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

  2. 教程全部用于TFS内部部署,而不是VSTS。由于事件订阅是服务器端插件,但托管了VSTS,因此无法在服务器端运行订阅。 VSTS不支持.Net事件订阅。

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

  4. 支持的活动:

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

    所以,你可以把Harshil Lodhi的建议作为一种解决方法。