private async Task <FixedEvent[]> fixMostRecentDeploymentsOnEntities(dynamic entities, int timespan) { Log.Info("fixMostRecentDeploymentsOnEntities: Start"); if (entities.Count == 0) { this.Log.Info("fixMostRecentDeploymentsOnEntities: No entites passed, aborting"); return(new FixedEvent[0]); } var returnArray = new List <FixedEvent>(); dynamic[] mostRecentEvents = await getMostRecentDeploymentOnEntity(entities, timespan); this.Log.Info("fixMostRecentDeploymentsOnEntities: # of Most Recent Deployment Events: " + mostRecentEvents.Length); if (mostRecentEvents.Length > 0) { var vstsHelper = new VSTSHelper { VSTSUrl = this.DTVSTSUrl, VSTSPAT = this.DTVSTSPAT, VSTSReleaseApiUrl = this.VSTSReleaseApiUrl, Log = this.Log }; this.Log.Info("fixMostRecentDeploymentsOnEntities: Iterating through deployment events and rolling back"); foreach (var deployEvent in mostRecentEvents) { this.Log.Info("fixMostRecentDeploymentsOnEntities: processing Problem event: " + deployEvent); var releaseId = int.Parse(deployEvent?.deploymentVersion.Value); var vstsTeamProject = deployEvent?.deploymentProject.Value; // find the environment value within the array of tags var environment = getEnvironmentTagValue(deployEvent); this.Log.Info("fixMostRecentDeploymentsOnEntities: Rolling back release from VSTS"); this.Log.Info("fixMostRecentDeploymentsOnEntities: releaseId: " + releaseId); this.Log.Info("fixMostRecentDeploymentsOnEntities: vstsTeamProject: " + vstsTeamProject); this.Log.Info("fixMostRecentDeploymentsOnEntities: environment: " + environment); var rollbackId = vstsHelper.ReleaseProblemDetected(vstsTeamProject, releaseId, environment); returnArray.Add(new FixedEvent { RollbackReleaseId = rollbackId, OrigEvent = deployEvent }); } this.Log.Info("fixMostRecentDeploymentsOnEntities: Done"); return(returnArray.ToArray()); } else { throw new Exception("fixMostRecentDeploymentsOnEntities: Missing PID"); } }
private async Task <FixedEvent[]> fixMostRecentDeploymentsOnEntities(dynamic entities, int timespan) { Log.Info("Starting fixMostRecentDeploymentsOnEntities"); if (entities.Count == 0) { this.Log.Info("No entites passed to getRecentDeploymentsOnEntities"); return(new FixedEvent[0]); } var returnArray = new List <FixedEvent>(); dynamic[] mostRecentEvents = await getMostRecentDeploymentOnEntity(entities, timespan); this.Log.Info("Found Most Recent Deployment Events: " + mostRecentEvents.Length); var vstsHelper = new VSTSHelper { VSTSUrl = this.DTVSTSUrl, VSTSPAT = this.DTVSTSPAT, Log = this.Log }; this.Log.Info("Iterating through deployment events and rolling back"); foreach (var problemEvent in mostRecentEvents) { this.Log.Info("Problem event: " + problemEvent); var releaseId = int.Parse(problemEvent?.deploymentVersion.Value); var vstsTeamProject = problemEvent?.deploymentProject.Value; var environment = problemEvent?.tags?[0]?.value.Value; // I want to use a custom event. Need to experiment //var releaseName = problemEvent?.customProperties?.VSTSReleaseName.Value; //var releaseId = problemEvent?.customProperties?.ReleaseId.Value; //var vstsTeamProject = problemEvent?.customProperties?.VSTSTeamProject.Value; //var environment = problemEvent?.customProperties?.VSTSEnvironment.Value; this.Log.Info("Rolling back release from VSTS"); var rollbackId = vstsHelper.ReleaseProblemDetected(vstsTeamProject, releaseId, environment); returnArray.Add(new FixedEvent { RollbackReleaseId = rollbackId, OrigEvent = problemEvent }); } this.Log.Info("Done with fixMostRecentDeploymentsOnEntities"); return(returnArray.ToArray()); }