【问题标题】: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