/// <summary> /// Builds a DeploymentResource for the release and environment passed, creates what steps to skip based on a string list. /// </summary> /// <param name="octRepository">The repository to call against.</param> /// <param name="release">Release to deploy.</param> /// <param name="environment">Environment to deploy to.</param> /// <param name="comment">Comment for the deployment.</param> /// <param name="formValues">Form value variable dictionary.</param> /// <param name="guidedFailure">Enable Guided Failure.</param> /// <param name="skippedSteps">Steps to skip.</param> /// <param name="dateToDeploy">Deployment Date.</param> /// <returns>DeploymentResource.</returns> public static DeploymentResource BuildDeployment(OctopusRepository octRepository, ReleaseResource release, EnvironmentResource environment, string comment, Dictionary <string, string> formValues, bool guidedFailure, IEnumerable <string> skippedSteps, DateTimeOffset?dateToDeploy) { var machineIDs = new ReferenceCollection(); var skippedStepIDs = new ReferenceCollection(); var projectSteps = StepHelper.GetReleaseEnvironmentDeploymentSteps(octRepository, release, environment); var skippedStepList = projectSteps.Where(p => skippedSteps.Any(s => s.Equals(p.ActionName, StringComparison.OrdinalIgnoreCase))).Select(d => d.ActionId); skippedStepIDs.ReplaceAll(skippedStepList); var releaseTemplate = octRepository.Releases.GetTemplate(release); var deploymentPromotionTarget = releaseTemplate.PromoteTo.SingleOrDefault(x => x.Id.Equals(environment.Id, StringComparison.OrdinalIgnoreCase)); var deploymentPreview = octRepository.Releases.GetPreview(deploymentPromotionTarget); foreach (var element in deploymentPreview.Form.Elements) { var variableInput = element.Control as VariableValue; if (variableInput != null) { var variableValue = formValues[variableInput.Label] ?? formValues[variableInput.Name]; if (string.IsNullOrWhiteSpace(variableValue) && element.IsValueRequired) { throw new ArgumentException(string.Format(ErrorStrings.MissingRequiredVar, variableInput.Label ?? variableInput.Name, ResourceStrings.FormValuesArgException)); } } } var deploymentResource = new DeploymentResource { EnvironmentId = environment.Id, SkipActions = skippedStepIDs, ReleaseId = release.Id, ForcePackageDownload = false, UseGuidedFailure = guidedFailure, SpecificMachineIds = machineIDs, ForcePackageRedeployment = true, FormValues = formValues, QueueTime = dateToDeploy, Comments = comment }; return(deploymentResource); }