private IEnumerable<IBuildDetail> GetBuilds(IBuildServer server, string status, DateTime started, DateTime finished, string collection) { var query = server.CreateBuildDetailSpec(collection); query.Status = (BuildStatus)Enum.Parse(typeof(BuildStatus), status); query.MinFinishTime = started; query.MaxFinishTime = finished; return server.QueryBuilds(query).Builds; }
private IBuildDetail GetLatestBuildDetails(IBuildServer buildServer, IBuildDefinition def) { IBuildDetailSpec spec = buildServer.CreateBuildDetailSpec(_configuration.TfsTeamProjectName, def.Name); spec.MaxBuildsPerDefinition = 1; spec.QueryOrder = BuildQueryOrder.FinishTimeDescending; var builds = buildServer.QueryBuilds(spec); return builds.Builds.FirstOrDefault(); }
private static IBuildDetail Arrange(MockRepository mockRepository) { IBuildDetail mockBuildDetailForCurrentBuild = mockRepository.DynamicMock <IBuildDetail>(); IBuildServer mockBuildServer = mockRepository.DynamicMock <IBuildServer>(); IBuildDetailSpec mockBuildDetailSpec = mockRepository.DynamicMock <IBuildDetailSpec>(); IBuildQueryResult mockBuildQueryResult = mockRepository.DynamicMock <IBuildQueryResult>(); ArrayList previousBuildsList = new ArrayList(); IBuildDetail[] previousBuilds = (IBuildDetail[])previousBuildsList.ToArray(typeof(IBuildDetail)); mockRepository.Record(); Expect.Call(mockBuildDetailForCurrentBuild.BuildServer).Return(mockBuildServer); Expect.Call(mockBuildDetailForCurrentBuild.TeamProject).Return("TeamProjectName"); Expect.Call(mockBuildServer.CreateBuildDetailSpec("TeamProjectName")).Return(mockBuildDetailSpec); Expect.Call(mockBuildServer.QueryBuilds(mockBuildDetailSpec)).Return(mockBuildQueryResult); Expect.Call(mockBuildQueryResult.Builds).Return(previousBuilds); return(mockBuildDetailForCurrentBuild); }
private void updateBuildNumber(int testPlanId) { //Define the variables string serverurl = Collection; Uri configurationServerUri = new Uri(serverurl); string project = _ProjectName; int myPlansId = testPlanId; try { //Get the build uri needed from build number TfsTeamProjectCollection tfsserv = new TfsTeamProjectCollection(configurationServerUri); Uri buildUri = null; IBuildServer buildServer = (IBuildServer)tfsserv.GetService(typeof(IBuildServer)); IBuildDetailSpec detailSpec = buildServer.CreateBuildDetailSpec(project); detailSpec.MaxBuildsPerDefinition = 1; detailSpec.QueryOrder = BuildQueryOrder.FinishTimeDescending; IBuildQueryResult results = buildServer.QueryBuilds(detailSpec); if (results.Builds.Length == 1) { IBuildDetail detail = results.Builds[0]; buildUri = detail.Uri; } //Update the test plan ITestManagementTeamProject proj = GetProject(serverurl, project); ITestPlan plan = proj.TestPlans.Find(myPlansId); Console.WriteLine("Test Plan: {0}", plan.Name); Console.WriteLine("Plan ID: {0}", plan.Id); Console.WriteLine("Previous Build Uri: {0}", plan.PreviousBuildUri); Console.WriteLine("Build Currently In Use: {0}", plan.BuildNumber); plan.BuildUri = buildUri; Console.WriteLine("\n Build updated in Test Plan \n"); Console.WriteLine("Build Currently In Use: {0}", plan.BuildNumber); plan.Save(); } catch (Exception e) { Console.WriteLine("\n There was an error \n"); Console.WriteLine(e); } }
private static IBuildDetail[] RetourneNbBuildDef(IBuildServer _bs, string TeamProject, IBuildDefinition buildDefinition, int nbMax) { IBuildDetailSpec def = _bs.CreateBuildDetailSpec(TeamProject); // only bring back the last 100 deleted builds def.MaxBuildsPerDefinition = nbMax; // query for only deleted builds def.QueryDeletedOption = QueryDeletedOption.OnlyDeleted; // Last deleted should be returned 1st def.QueryOrder = BuildQueryOrder.FinishTimeDescending; // Only look for deleted builds in the chosen build definition def.DefinitionSpec.Name = buildDefinition.Name; // Bring back deleted builds from any state def.Status = BuildStatus.All; // Pass this query for processing to the build service IBuildDetail[] builds = _bs.QueryBuilds(def).Builds; return(builds); }
/// <summary> /// Returns available builds in the form of build numbers for a given team project and build definition. /// </summary> /// <param name="teamProject">Team project name</param> /// <param name="buildDefinition">Build definition name</param> /// <returns>List of strings</returns> public IEnumerable <string> GetAvailableBuildNumbers(string teamProject, string buildDefinition) { if (null == teamProject) { throw new ArgumentNullException("teamProject"); } if (null == buildDefinition) { throw new ArgumentNullException("buildDefinition"); } var spec = _buildServer.CreateBuildDetailSpec(teamProject, buildDefinition); spec.InformationTypes = new string[] { }; return(new List <string>(_buildServer.QueryBuilds(spec).Builds.Select(x => x.BuildNumber))); }
private IBuildDetail GetBuild(IBuildServer buildServer, CatalogNode teamProjectNode, IBuildDefinition def, DateTime filterDate) { IBuildDetail build = null; try { var buildDetailSpec = buildServer.CreateBuildDetailSpec(teamProjectNode.Resource.DisplayName, def.Name); buildDetailSpec.MaxBuildsPerDefinition = 1; buildDetailSpec.QueryOrder = BuildQueryOrder.FinishTimeDescending; buildDetailSpec.MinFinishTime = filterDate; build = buildServer.QueryBuilds(buildDetailSpec).Builds.FirstOrDefault(); } catch (Exception e) { LogService.WriteError(e); throw; } return build; }
private static void DeleteBuildsForDefinition(ApplicationTask task, IBuildServer buildServer, int step, BuildDefinitionInfo buildDefinition) { var buildDetailSpec = buildServer.CreateBuildDetailSpec(new[] { buildDefinition.Uri, }); var buildsToDelete = buildServer.QueryBuilds(buildDetailSpec).Builds; if (buildsToDelete.Any()) { task.SetProgress(step, string.Format(CultureInfo.CurrentCulture, "Deleting {0} builds for definition \"{1}\" in Team Project \"{2}\"", buildsToDelete.Count(), buildDefinition.Name, buildDefinition.TeamProject)); foreach (var buildToDelete in buildsToDelete) { try { buildToDelete.Delete(DeleteOptions.All); } catch (Exception exc) { task.SetWarning(string.Format(CultureInfo.CurrentCulture, "An error occurred while deleting build number \"{0}\" for definition \"{1}\" in Team Project \"{2}\"", buildToDelete.BuildNumber, buildDefinition.Name, buildDefinition.TeamProject), exc); } } } }
/// <summary> /// Gets the latest build number /// </summary> /// <param name="projectName"></param> /// <returns></returns> public string GetLatestBuildNumber() { (new Logger()) .SetMessage("Querying build definitions.") .SetLoggingType(Logger.Type.Information) .Display(); IBuildServer buildServer = this.projectCollection.GetService <IBuildServer>(); IBuildDetailSpec buildSpec = buildServer.CreateBuildDetailSpec(projectName); buildSpec.MaxBuildsPerDefinition = 1; buildSpec.QueryOrder = BuildQueryOrder.FinishTimeDescending; IBuildQueryResult query = buildServer.QueryBuilds(buildSpec); if (query.Builds.Count() == 0) { return(null); } IBuildDetail detail = query.Builds[0]; return(detail.BuildNumber); }
public IEnumerable <BuildInformation> GetBuilds(string projectName, string buildDefinition, DateTime minFinishedTime) { IBuildDetailSpec buildDetailSpec = buildServer.CreateBuildDetailSpec(projectName, buildDefinition); buildDetailSpec.MaxBuildsPerDefinition = 5; buildDetailSpec.QueryOrder = BuildQueryOrder.StartTimeDescending; buildDetailSpec.MinFinishTime = minFinishedTime.AddSeconds(1); var builds = buildServer.QueryBuilds(buildDetailSpec); var tests = testManagementService.GetTeamProject(projectName); return(builds.Builds .Select(b => new { Build = b, TestRuns = tests.TestRuns.ByBuild(b.Uri).ToList(), StaticAnalysis = b.GetStaticAnalysisInfo() ?? new StaticAnalysisInfo(), CheckinComments = b.GetCheckinComments(), WorkItemTitles = b.GetWorkItemTitles() }) .Select(b => new BuildInformation { Uri = b.Build.Uri.ToString(), StartedAt = b.Build.StartTime, FinishedAt = b.Build.FinishTime, TriggeredBy = RemoveDomainFromUsername(b.Build.RequestedFor), Status = TranslateBuildStatus(b.Build.Status).ToString(), TestsFailed = b.TestRuns.Select(run => run.Statistics.FailedTests).Sum(), TestsPassed = b.TestRuns.Select(run => run.Statistics.PassedTests).Sum(), TestsTotal = b.TestRuns.Select(run => run.Statistics.TotalTests).Sum(), CodeAnalysisErrors = b.StaticAnalysis.StaticAnalysisErrors, CodeAnalysisWarnings = b.StaticAnalysis.StaticAnalysisWarnings, CompilerWarnings = b.StaticAnalysis.CompilationWarnings, CheckinComments = string.Join(" +++ ", b.CheckinComments), WorkItemTitles = string.Join(", ", b.WorkItemTitles), }).ToList()); }
internal static void Add_Builds(XlHlp.XlLocation insertAt, Options_AZDO_TFS options, IBuildServer buildServer, TeamProject teamProject) { Int64 startTicks = Log.APPLICATION("Enter", Common.LOG_CATEGORY); var builds = buildServer.QueryBuilds(teamProject.Name); foreach (IBuildDetail buildDetail in builds) { insertAt.ClearOffsets(); XlHlp.AddOffsetContentToCell(insertAt.AddOffsetColumn(), string.Format("{0}", buildDetail.BuildController.Name)); XlHlp.AddOffsetContentToCell(insertAt.AddOffsetColumn(), string.Format("{0}", buildDetail.LabelName)); XlHlp.AddOffsetContentToCell(insertAt.AddOffsetColumn(), string.Format("{0}", buildDetail.StartTime)); XlHlp.AddOffsetContentToCell(insertAt.AddOffsetColumn(), string.Format("{0}", buildDetail.FinishTime)); XlHlp.AddOffsetContentToCell(insertAt.AddOffsetColumn(), string.Format("{0}", buildDetail.BuildFinished)); insertAt.IncrementRows(); } Log.APPLICATION("Exit", Common.LOG_CATEGORY, startTicks); }
// Get All Deleted Builds for the selected build definition private void cbBuildDef_SelectionChanged(object sender, SelectionChangedEventArgs e) { cbBuilds.Items.Clear(); // bdef is the selected build definition var bdef = (((ComboBox)sender).SelectedItem) as IBuildDefinition; _builddef = bdef; if (bdef != null) { // _bs = IBuildServer service, create a new query IBuildDetailSpec def = _bs.CreateBuildDetailSpec(_selectedTeamProject); // only bring back the last 100 deleted builds def.MaxBuildsPerDefinition = 100; // query for only deleted builds def.QueryDeletedOption = QueryDeletedOption.OnlyDeleted; // Last deleted should be returned 1st def.QueryOrder = BuildQueryOrder.FinishTimeDescending; // Only look for deleted builds in the chosen build definition def.DefinitionSpec.Name = bdef.Name; // Bring back deleted builds from any state def.Status = BuildStatus.All; // Pass this query for processing to the build service IBuildDetail[] builds = _bs.QueryBuilds(def).Builds; foreach (IBuildDetail build in builds) { cbBuilds.Items.Add(build.BuildNumber); } cbBuilds.IsEnabled = true; btnDelete.IsEnabled = true; } }
private void GetBuildResults(TeamProject teamProject, IBuildServer buildServer, IEnumerable<IBuildDefinition> buildDefinitions) { Parallel.ForEach(buildDefinitions, buildDefinition => { IBuildDetailSpec buildDetailSpec = buildServer.CreateBuildDetailSpec(teamProject.Name, buildDefinition.Name); buildDetailSpec.MaxBuildsPerDefinition = 5; buildDetailSpec.QueryOrder = BuildQueryOrder.FinishTimeDescending; var buildResult = buildServer.QueryBuilds(buildDetailSpec); try { Application.Current.Dispatcher.BeginInvoke(new Action(() => BuildResults.Add(buildResult))); } catch (NullReferenceException) { } }); }
static void QueryBuildHistory(IBuildServer buildServer) { Console.WriteLine(); Console.WriteLine("QueryBuildHistory:"); IBuildDetailSpec spec = buildServer.CreateBuildDetailSpec("Contoso"); spec.MinFinishTime = DateTime.Now.AddDays(-5); IBuildDetail[] builds = buildServer.QueryBuilds(spec).Builds; foreach (IBuildDetail build in builds) { Console.WriteLine(build.BuildNumber); } }
/// <summary> /// Discover all available versions. /// </summary> /// <param name="name">The component name</param> /// <returns>A list with all versions</returns> public IEnumerable <IComponentVersion> GetAvailableVersions(IComponentName name) { var versList = new List <IComponentVersion>(); Logger.Instance().Log(TraceLevel.Info, "{0}: Querying available component versions...", ResolverType); var teamProject = _versionControlServer.TryGetTeamProject(name.TeamProject); if (teamProject == null) { Logger.Instance().Log( TraceLevel.Info, "{0}: Could not find team project {1} on version control server for team project collection {2}", ResolverType, name.TeamProject, ResolverSettings.GetSetting(ResolverValidSettings.TeamProjectCollectionUrl)); throw new InvalidComponentException( string.Format( "Could not find team project {0} on version control server for team project collection {1}", name.TeamProject, ResolverSettings.GetSetting(ResolverValidSettings.TeamProjectCollectionUrl))); } var buildDef = _buildServer.GetBuildDefinition(teamProject.Name, name.BuildDefinition); if (buildDef == null) { Logger.Instance().Log( TraceLevel.Info, "{0}: Could not find build definition {1} for team project {2} on version control server for tfs {3}", ResolverType, name.BuildDefinition, name.TeamProject, ResolverSettings.GetSetting(ResolverValidSettings.TeamProjectCollectionUrl)); throw new InvalidComponentException( string.Format( "Could not find build definition {0} for team project {1} on version control server for tfs {2}", name.BuildDefinition, name.TeamProject, ResolverSettings.GetSetting(ResolverValidSettings.TeamProjectCollectionUrl))); } // Query all builds with this teamProject and build definition name // BuildNumber xor (BuildQuality or BuildStatus) = version var spec = _buildServer.CreateBuildDetailSpec(buildDef); spec.InformationTypes = new string[] { }; var details = _buildServer.QueryBuilds(spec); foreach (var buildResult in details.Builds) { List <string> availableBuildQuality = null; if (buildResult.Quality != null) { availableBuildQuality = new List <string> { buildResult.Quality }; } var availableBuildStatus = new List <string> { buildResult.Status.ToString() }; var vers = new ComponentVersion(buildResult.BuildNumber, availableBuildStatus, availableBuildQuality, null); versList.Add(vers); Logger.Instance().Log(TraceLevel.Info, "{0}: Found build {1}", ResolverType, vers.ToString()); } Logger.Instance().Log(TraceLevel.Info, "{0}: Querying component versions finished successfully", ResolverType); return(versList); }
private IEnumerable <IBuildDetail> QueryAllBuilds() { var projects = _structureService.ListProjects(); return(projects.SelectMany(project => _buildServer.QueryBuilds(project.Name))); }
private IBuildDetail GetBuild(IBuildServer buildServer, CatalogNode teamProjectNode, IBuildDefinition def, DateTime filterDate) { IBuildDetail build = null; try { var buildDetailSpec = buildServer.CreateBuildDetailSpec(teamProjectNode.Resource.DisplayName, def.Name); buildDetailSpec.MaxBuildsPerDefinition = 1; buildDetailSpec.QueryOrder = BuildQueryOrder.FinishTimeDescending; buildDetailSpec.MinFinishTime = filterDate; build = buildServer.QueryBuilds(buildDetailSpec).Builds.FirstOrDefault(); } catch (Exception e) { LogService.WriteError(e); throw; } return build; }
private static IBuildQueryResult GetSprintBuilds(IBuildServer buildService, string teamProject, string buildName, DateTime startDate, DateTime endDate) { var buildSpec = buildService.CreateBuildDetailSpec(teamProject); buildSpec.MinFinishTime = startDate; buildSpec.MaxFinishTime = endDate; buildSpec.Status = BuildStatus.All; buildSpec.QueryOrder = BuildQueryOrder.FinishTimeAscending; buildSpec.DefinitionSpec.Name = buildName; buildSpec.MaxBuildsPerDefinition = 1500; var builds = buildService.QueryBuilds(buildSpec); return builds; }
private TimeSpan GetLastSuccesfulBuildTime(IBuildServer buildServer, CatalogNode teamProjectNode, IBuildDefinition def) { var buildTime = new TimeSpan(); try { var inProgressBuildDetailSpec = buildServer.CreateBuildDetailSpec(teamProjectNode.Resource.DisplayName, def.Name); inProgressBuildDetailSpec.Status = BuildStatus.Succeeded; inProgressBuildDetailSpec.MaxBuildsPerDefinition = 1; inProgressBuildDetailSpec.QueryOrder = BuildQueryOrder.FinishTimeDescending; var lastSuccesfulBuild = buildServer.QueryBuilds(inProgressBuildDetailSpec).Builds.FirstOrDefault(); if (lastSuccesfulBuild != null) { buildTime = lastSuccesfulBuild.FinishTime - lastSuccesfulBuild.StartTime; } } catch (Exception e) { LogService.WriteError(e); throw; } return buildTime; }