2016-04-13 16 views
1

背景:

我有一個內部TFS 2015 Update 1服務器。在新的TFS構建風格中,構建通過網絡共享are not deleted when the build is deleted過期保留策略完成的刪除。我們的設置不能使用基於服務器的丟棄,我們必須使用網絡共享丟棄。如何獲得BuildDestroyedEvent的通知

作爲解決方法,我試圖編寫一個服務,在構建過期並被刪除時將會收到通知,然後可以爲我刪除關聯的網絡共享。

問題:

我發現了.NET TFS client libraries,在Microsoft.TeamFoundationServer.Client NuGet包有一個Microsoft.TeamFoundation.Build.WebApi.Events.BuildDestroyedEvent類長相酷似我需要什麼。但我無法弄清楚如何「訂閱」該事件。

我找到了a good tutorial使用Microsoft.TeamFoundationServer.ExtendedClient API,它顯示訂閱WorkItemChangedEvent與Web回調。但是,當我嘗試訪問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. collectionUri對於VSTS總是https://xxx.visualstudio.com/DefaultCollection,其他格式無法識別。

  2. 本教程均適用於TFS內部部署,而不是VSTS。由於事件訂閱是服務器端插件,但託管VSTS,因此無法在服務器端運行訂閱。 .Net事件訂閱在VSTS中不受支持。

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

支持的事件:

  • 構建完成
  • 碼推(對於Git的團隊項目)
  • 拉請求創建或更新(對於Git的團隊項目)中
  • 代碼進行覈對( TFVC團隊項目)
  • 創建,更新,刪除,恢復或評論的工作項目
  • 發佈到團隊房間的消息

因此,您可以將Harshil Lodhi的建議作爲解決方法。

+0

對於點1,我在內部部署運行TFS,我試圖連接到本地運行TFS 2015年更新1(我們正計劃升級到更新2本週末)。另外,我還是想用'Microsoft.TeamFoundationServer.Client' NuGet包有什麼辦法「SUBCRIBE」要知道*** ***任何事件在'Microsoft.TeamFoundation.Build.WebApi.Events '命名空間。 –

+0

我認爲只有作爲服務鉤子的一部分可用的事件才能訂閱。您可以轉到TFS Web UI和服務掛鉤選項卡中的設置來查看事件。 –

+0

那些充當插件而不是外部服務的東西呢,他們沒有獲得更多的訪問權限嗎?我寫的「服務」不需要是外部服務,我可以把它寫成TFS的插件,我只是不知道如何訪問信息。 –