public ManualIntervention RejectManualIntervention() { string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; // Get a release client instance VssConnection connection = Context.Connection; ReleaseHttpClient releaseClient = connection.GetClient <ReleaseHttpClient>(); ManualInterventionUpdateMetadata manualInterventionUpdateMetadata = new ManualInterventionUpdateMetadata() { Status = ManualInterventionStatus.Rejected, Comment = "Reject MI" }; IList <ManualIntervention> manualInterventions = null; // Get all manual interventions ClientSampleHelpers.Retry( TimeSpan.FromMinutes(2), TimeSpan.FromSeconds(5), () => { manualInterventions = releaseClient.GetManualInterventionsAsync(project: projectName, releaseId: this._newlyCreatedRelease2.Id).Result; return(manualInterventions.Count > 0); }); // Update a manual intervention ManualIntervention manualIntervention = releaseClient.UpdateManualInterventionAsync(manualInterventionUpdateMetadata: manualInterventionUpdateMetadata, project: projectName, releaseId: this._newlyCreatedRelease2.Id, manualInterventionId: manualInterventions.FirstOrDefault().Id).Result; Context.Log("{0} {1}", manualIntervention.Id.ToString().PadLeft(6), manualIntervention.Name); return(manualIntervention); }
public IList <ManualIntervention> GetManualInterventions() { string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; // Get a release client instance VssConnection connection = Context.Connection; ReleaseHttpClient releaseClient = connection.GetClient <ReleaseHttpClient>(); IList <ManualIntervention> manualInterventions = null; // Get all manual interventions ClientSampleHelpers.Retry( TimeSpan.FromMinutes(2), TimeSpan.FromSeconds(5), () => { manualInterventions = releaseClient.GetManualInterventionsAsync(project: projectName, releaseId: this._newlyCreatedRelease1.Id).Result; return(manualInterventions.Count > 0); }); foreach (ManualIntervention manualIntervention in manualInterventions) { Context.Log("{0} {1}", manualIntervention.Id.ToString().PadLeft(6), manualIntervention.Name); } this._manualInterventions = manualInterventions; return(manualInterventions); }
public System.IO.Stream GetLogsOfReleaseTask() { string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; // Get a release client instance VssConnection connection = Context.Connection; ReleaseHttpClient releaseClient = connection.GetClient <ReleaseHttpClient>(); // Get Release Defintion ReleaseDefinition releaseDefinition = releaseClient.GetReleaseDefinitionAsync(project: projectName, definitionId: newlyCreatedReleaseDefinitionId).Result; // Get all completed environment releases. // environmentStatusFilter values Undefined = 0, NotStarted = 1, InProgress = 2, Succeeded = 4, Canceled = 8, Rejected = 16, Qeued = 32, Scheduled = 64, PartiallySucceeded = 128 List <WebApiRelease> releases = new List <WebApiRelease>(); ClientSampleHelpers.Retry( TimeSpan.FromMinutes(2), TimeSpan.FromSeconds(5), () => { releases = releaseClient.GetReleasesAsync(project: projectName, definitionId: releaseDefinition.Id, definitionEnvironmentId: releaseDefinition.Environments.First().Id, expand: ReleaseExpands.Environments, environmentStatusFilter: 4).Result; return(releases.Count > 0); }); // Get first release first environment first deployment first task log WebApiRelease release = releaseClient.GetReleaseAsync(project: projectName, releaseId: releases.First().Id).Result; this.completedReleaseId = release.Id; ReleaseEnvironment releaseEnvironment = release.Environments.First(); ReleaseDeployPhase deployPhase = releaseEnvironment.DeploySteps.First().ReleaseDeployPhases.FirstOrDefault(); ReleaseTask task = deployPhase.DeploymentJobs.First().Tasks.First(); System.IO.Stream taskLog = releaseClient.GetTaskLogAsync(project: projectName, releaseId: release.Id, environmentId: releaseEnvironment.Id, releaseDeployPhaseId: deployPhase.Id, taskId: task.Id).Result; Context.Log("{0} {1}", release.Id.ToString().PadLeft(6), release.Id); return(taskLog); }
public ReleaseGates IgnoreGate() { string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; string gateName = "Query Work Items"; ReleaseDefinitionGatesStep releaseDefinitionGatesStep = new ReleaseDefinitionGatesStep { Gates = new List <ReleaseDefinitionGate> { new ReleaseDefinitionGate { Tasks = new List <WorkflowTask> { new WorkflowTask { Enabled = true, Name = gateName, TaskId = new Guid("f1e4b0e6-017e-4819-8a48-ef19ae96e289"), Version = "0.*", Inputs = new Dictionary <string, string> { { "queryId", "c871ca91-e30c-43a0-9306-97a2be93861e" }, { "maxThreshold", "6" }, { "minThreshold", "2" } } } } } }, GatesOptions = new ReleaseDefinitionGatesOptions { IsEnabled = true, MinimumSuccessDuration = 2, SamplingInterval = 5, StabilizationTime = 10, Timeout = 60 }, Id = 0 }; ReleaseDefinition definition = new ReleaseDefinition() { Name = releaseDefinitionName, Revision = 1, Environments = new List <ReleaseDefinitionEnvironment>() { new ReleaseDefinitionEnvironment() { Name = "PROD", Conditions = new List <Condition>() { new Condition() { ConditionType = ConditionType.Event, Name = "ReleaseStarted" } }, DeployPhases = new List <DeployPhase>() { new RunOnServerDeployPhase() { Name = "Agentless phase", Rank = 1, WorkflowTasks = new List <WorkflowTask>() { new WorkflowTask() { Name = "Manual Intervention", TaskId = new Guid("bcb64569-d51a-4af0-9c01-ea5d05b3b622"), Version = "8.*", Enabled = true } } } }, PreDeployApprovals = new ReleaseDefinitionApprovals() { Approvals = new List <ReleaseDefinitionApprovalStep>() { new ReleaseDefinitionApprovalStep() { IsAutomated = true, Rank = 1, } } }, PostDeployApprovals = new ReleaseDefinitionApprovals() { Approvals = new List <ReleaseDefinitionApprovalStep>() { new ReleaseDefinitionApprovalStep() { IsAutomated = true, Rank = 1 } } }, RetentionPolicy = new EnvironmentRetentionPolicy() { DaysToKeep = 30, ReleasesToKeep = 3, RetainBuild = true }, PreDeploymentGates = releaseDefinitionGatesStep } } }; // Get a release client instance VssConnection connection = Context.Connection; ReleaseHttpClient releaseClient = connection.GetClient <ReleaseHttpClient>(); // create a release definition ReleaseDefinition releaseDefinition = releaseClient.CreateReleaseDefinitionAsync(project: projectName, releaseDefinition: definition).Result; this._newlyCreatedReleaseDefinitionId = releaseDefinition.Id; // create a release WebApiRelease release = ReleasesSample.CreateRelease(releaseClient, _newlyCreatedReleaseDefinitionId, projectName); Context.Log("{0} {1}", release.Id.ToString().PadLeft(6), release.Name); // Wait till deployment moves to evaluation gates state ClientSampleHelpers.Retry( TimeSpan.FromMinutes(2), TimeSpan.FromSeconds(5), () => { release = releaseClient.GetReleaseAsync(project: projectName, releaseId: release.Id).Result; return(release != null && release.Environments.First().DeploySteps.FirstOrDefault().OperationStatus == DeploymentOperationStatus.EvaluatingGates); }); // Ignore the gate GateUpdateMetadata gateUpdateMetadata = new GateUpdateMetadata { Comment = "Ignore gate", GatesToIgnore = new List <string> { gateName } }; int gateStepId = release.Environments.FirstOrDefault().DeploySteps.FirstOrDefault().PreDeploymentGates.Id; ReleaseGates releaseGates = releaseClient.UpdateGatesAsync(gateUpdateMetadata: gateUpdateMetadata, project: projectName, gateStepId: gateStepId).Result; Context.Log("{0} {1}", releaseGates.Id.ToString().PadLeft(6), releaseGates.Id); return(releaseGates); }
public List <ReleaseTaskAttachment> GetReleaseAttachment() { string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; ReleaseDefinition definition = new ReleaseDefinition() { Name = releaseDefinitionName, Revision = 1, Environments = new List <ReleaseDefinitionEnvironment>() { new ReleaseDefinitionEnvironment() { Name = "PROD", Conditions = new List <Condition>() { new Condition() { ConditionType = ConditionType.Event, Name = "ReleaseStarted" } }, DeployPhases = new List <DeployPhase>() { new AgentBasedDeployPhase() { Name = "Run on agent", Rank = 1, DeploymentInput = new AgentDeploymentInput() { QueueId = 1 }, WorkflowTasks = new List <WorkflowTask> { new WorkflowTask { Name = taskName, Enabled = true, TimeoutInMinutes = 0, Inputs = new Dictionary <string, string> { { "targetType", "inline" }, { "script", "New-Item -Path 'newfile.txt' -ItemType File\n\nWrite-Host \"##vso[task.addattachment type=myattachmenttype;name=myattachmentname;]$(SYSTEM.DEFAULTWORKINGDIRECTORY)\\newfile.txt\"" } }, TaskId = new Guid("e213ff0f-5d5c-4791-802d-52ea3e7be1f1"), Version = "2.*", DefinitionType = "task", Condition = "succeeded()", } } } }, PreDeployApprovals = new ReleaseDefinitionApprovals() { Approvals = new List <ReleaseDefinitionApprovalStep>() { new ReleaseDefinitionApprovalStep() { IsAutomated = true, Rank = 1 } } }, PostDeployApprovals = new ReleaseDefinitionApprovals() { Approvals = new List <ReleaseDefinitionApprovalStep>() { new ReleaseDefinitionApprovalStep() { IsAutomated = true, Rank = 1 } } }, RetentionPolicy = new EnvironmentRetentionPolicy() { DaysToKeep = 30, ReleasesToKeep = 3, RetainBuild = true } } } }; // Get a release client instance VssConnection connection = Context.Connection; ReleaseHttpClient releaseClient = connection.GetClient <ReleaseHttpClient>(); // create a release definition ReleaseDefinition releaseDefinition = releaseClient.CreateReleaseDefinitionAsync(project: projectName, releaseDefinition: definition).Result; this._newlyCreatedReleaseDefinitionId = releaseDefinition.Id; Context.Log("{0} {1} {2}", releaseDefinition.Id.ToString().PadLeft(6), releaseDefinition.Name, projectName); // create a release WebApiRelease release = ReleasesSample.CreateRelease(releaseClient, _newlyCreatedReleaseDefinitionId, projectName); Context.Log("{0} {1}", release.Id.ToString().PadLeft(6), release.Name); _newlyCreatedRelease = release.Id; // Wait till deployment completed ClientSampleHelpers.Retry( TimeSpan.FromMinutes(2), TimeSpan.FromSeconds(5), () => { release = releaseClient.GetReleaseAsync(project: projectName, releaseId: release.Id).Result; return(release != null && release.Environments.First().Status == EnvironmentStatus.Succeeded); }); // Get release task attachments ReleaseEnvironment environment = release.Environments.FirstOrDefault(); DeploymentAttempt deployStep = environment.DeploySteps.First(); Guid planId = deployStep.ReleaseDeployPhases.First().RunPlanId.Value; List <ReleaseTaskAttachment> releaseTaskAttachment = releaseClient.GetReleaseTaskAttachmentsAsync(project: projectName, releaseId: release.Id, environmentId: environment.Id, attemptId: deployStep.Attempt, planId: planId, type: "myattachmenttype").Result; Context.Log("{0} {1}", releaseTaskAttachment.First().Name.PadLeft(6), releaseTaskAttachment.First().Type); return(releaseTaskAttachment); }