private bool CheckDefinition() { if (this.TeamProject.Expression == null) { var buildDetail = this.ActivityContext.GetExtension <IBuildDetail>(); this.TeamProject.Set(this.ActivityContext, buildDetail.TeamProject); } IQueuedBuildSpec buildSpec = this.bs.CreateBuildQueueSpec(this.TeamProject.Get(this.ActivityContext), this.BuildDefinition.Get(this.ActivityContext)); IQueuedBuildQueryResult builds = this.bs.QueryQueuedBuilds(buildSpec); return(builds.QueuedBuilds.Any(this.IsQueuedBuildRunning)); }
/// <summary> /// http://stackoverflow.com/questions/10557814/how-to-get-a-specific-build-with-the-tfs-api /// </summary> /// <param name="TeamProject"></param> /// <param name="BuildDefinition"></param> /// <param name="BuildID"></param> /// <returns></returns> public string GetBuildStatus(TfsTeamProjectCollection tfs, string TeamProject, string BuildDefinition, int BuildID) { IBuildServer buildServer = (IBuildServer)tfs.GetService(typeof(IBuildServer)); string status = string.Empty; IQueuedBuildSpec qbSpec = buildServer.CreateBuildQueueSpec(TeamProject, BuildDefinition); IQueuedBuildQueryResult qbResults = buildServer.QueryQueuedBuilds(qbSpec); if (qbResults.QueuedBuilds.Length > 0) { IQueuedBuild build = qbResults.QueuedBuilds.Where(x => x.Id == BuildID).FirstOrDefault(); status = build.Status.ToString(); } return(status); }
public async Task Setup() { await Task.Run(() => _TFS = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(TFS_URL))); await Task.Run(() => _BuildServer = _TFS.GetService<IBuildServer>()); await Task.Run(() => _QueuedBuildSpec = _BuildServer.CreateBuildQueueSpec("*", "*")); }