async Task <DateTime> ImportVstsBuildsDataForSpecificDefinitionAsync( BuildManagement buildManagement, string branch, BuildDefinitionId buildDefinitionId, DateTime lastUpdate) { SqlConnection sqlConnection = null; try { sqlConnection = new SqlConnection(this.dbConnectionString); sqlConnection.Open(); IList <VstsBuild> buildResults = await buildManagement.GetBuildsAsync(new HashSet <BuildDefinitionId> { buildDefinitionId }, branch, lastUpdate); Console.WriteLine($"Query VSTS for branch [{branch}] and build definition [{buildDefinitionId.ToString()}]: last update={lastUpdate} => result count={buildResults.Count}"); DateTime maxLastChange = lastUpdate; foreach (VstsBuild build in buildResults.Where(r => r.HasResult())) { UpsertVstsBuildToDb(sqlConnection, build); if (build.LastChangedDate > maxLastChange) { maxLastChange = build.LastChangedDate; } } return(maxLastChange); } catch (Exception) { throw; } finally { sqlConnection?.Close(); } }
public static string DisplayName(this BuildDefinitionId buildDefinitionId) { Dictionary <BuildDefinitionId, string> buildDefinitionIdToDisplayNameMapping = new Dictionary <BuildDefinitionId, string> { { BuildDefinitionId.BuildImages, "Build Images" }, { BuildDefinitionId.CI, "CI" }, { BuildDefinitionId.EdgeletCI, "Edgelet CI" }, { BuildDefinitionId.EdgeletPackages, "Edgelet Packages" }, { BuildDefinitionId.EdgeletRelease, "Edgelet Release" }, { BuildDefinitionId.EndToEndTest, "End-to-End Test" }, { BuildDefinitionId.ImageRelease, "Image Release" }, { BuildDefinitionId.LibiohsmCI, "Libiohsm CI" }, }; return(buildDefinitionIdToDisplayNameMapping.ContainsKey(buildDefinitionId) ? buildDefinitionIdToDisplayNameMapping[buildDefinitionId] : buildDefinitionId.ToString()); }
async Task OpenBugsForFailingBuilds(BugManagement bugManagement, IList <VstsBuild> builds, string branch, BuildDefinitionId buildDefinitionId) { // Filter out the builds for which we have already made bugs builds = FilterBuildsByDate(builds); builds = FilterBuildsByStatus(builds); builds = FilterBuildsByExistingBugs(builds); Console.WriteLine($"Filtering builds complete. Creating bugs for {builds.Count} builds"); // Create the bugs Dictionary <string, string> buildIdToBugId = new Dictionary <string, string>(); foreach (VstsBuild build in builds) { try { string bugId = await bugManagement.CreateBugAsync(branch, build); buildIdToBugId.Add(build.BuildId, bugId); } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine("Create bug failed. Will retry later."); } } if (buildIdToBugId.Count == 0) { return; } Console.WriteLine($"Successfully created {buildIdToBugId.Count} bugs for {buildDefinitionId.ToString()} on {branch} branch"); // Add the created bugs to the db for tracking SqlConnection sqlConnection = null; try { sqlConnection = new SqlConnection(this.dbConnectionString); sqlConnection.Open(); foreach ((string buildId, string bugId) in buildIdToBugId) { UpsertVstsBugToDb(sqlConnection, buildId, bugId); } } catch (Exception) { throw; } finally { sqlConnection?.Close(); } }
async Task <IList <VstsBuild> > GetBuildsAndTrackLastUpdatedAsync(BuildManagement buildManagement, BuildDefinitionId buildDefinitionId, string branch) { Dictionary <BuildDefinitionId, DateTime> buildDefinitionIdToLastUpdate = this.buildLastUpdatePerBranchPerDefinition.GetIfExists(branch); if (buildDefinitionIdToLastUpdate == null) { buildDefinitionIdToLastUpdate = new Dictionary <BuildDefinitionId, DateTime>(); } DateTime lastUpdate = buildDefinitionIdToLastUpdate.GetIfExists(buildDefinitionId); IList <VstsBuild> buildResults = await buildManagement.GetBuildsAsync(new HashSet <BuildDefinitionId> { buildDefinitionId }, branch, lastUpdate); Console.WriteLine($"Query VSTS builds for branch [{branch}] and build definition [{buildDefinitionId.ToString()}]: last update={lastUpdate} => result count={buildResults.Count}"); DateTime maxLastChange = DateTime.MinValue; foreach (VstsBuild build in buildResults.Where(r => r.HasResult())) { if (build.LastChangedDate > maxLastChange) { maxLastChange = build.LastChangedDate; } } buildDefinitionIdToLastUpdate.Upsert(buildDefinitionId, maxLastChange); this.buildLastUpdatePerBranchPerDefinition.Upsert(branch, buildDefinitionIdToLastUpdate); return(buildResults); }
public static string DisplayName(this BuildDefinitionId buildDefinitionId) { var definitionIdToDisplayNameMapping = new Dictionary <BuildDefinitionId, string> { { BuildDefinitionId.BuildImages, "Build Images" }, { BuildDefinitionId.CI, "CI" }, { BuildDefinitionId.EdgeletCI, "Edgelet CI" }, { BuildDefinitionId.EdgeletPackages, "Edgelet Packages" }, { BuildDefinitionId.EdgeletRelease, "Edgelet Release" }, { BuildDefinitionId.EndToEndTest, "New E2E Test" }, { BuildDefinitionId.ImageRelease, "Image Release" }, { BuildDefinitionId.LibiohsmCI, "Libiothsm CI" }, { BuildDefinitionId.ConnectivityTest, "Connectivity Test" }, { BuildDefinitionId.LonghaulTestEnv1, "Longhaul Test" }, { BuildDefinitionId.LonghaulTestEnv2, "Longhaul Test Release Candidate" }, { BuildDefinitionId.LonghaulTestEnv3, "Longhaul Test Release" }, { BuildDefinitionId.StressTestEnv1, "Stress Test" }, { BuildDefinitionId.StressTestEnv2, "Stress Test Release Candidate" }, { BuildDefinitionId.StressTestEnv3, "Stress Test Release" }, }; return(definitionIdToDisplayNameMapping.ContainsKey(buildDefinitionId) ? definitionIdToDisplayNameMapping[buildDefinitionId] : buildDefinitionId.ToString()); }
public static string DisplayName(this BuildDefinitionId buildDefinitionId) { return(definitionIdToDisplayNameMapping.ContainsKey(buildDefinitionId) ? definitionIdToDisplayNameMapping[buildDefinitionId] : buildDefinitionId.ToString()); }