背景:
我有一個內部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
燒製的通知?
你想要實時刪除構建?如果不是這樣,那麼只需打電話來獲取構建以檢查它們是否被刪除的日常工作就可以工作。 –
好主意,我想我會使用,作爲一個備份計劃 –