I’m having a hard time removing an environment from a lifecycle. Here’s the code:
private static void RemoveEnvironmentFromLifecycle(OctopusRepository repo, EnvironmentResource environment, string lifecycleName)
{
var lifecycle = repo.GetLifecycle(lifecycleName);
lifecycle.RemoveEnvironment(environment);
if (_force)
repo.Lifecycles.Modify(lifecycle);
}
public static void RemoveEnvironment(this LifecycleResource lifecycle, EnvironmentResource environment)
{
var targets = lifecycle.Phases[0].OptionalDeploymentTargets;
if (!targets.Contains(environment.Id))
{
Program.Logger.Info("Environment '{0}' is not in lifecycle '{1}'.", environment.Name, lifecycle.Name);
return;
}
Program.Logger.Info("Removing environment '{0}' from lifecycle '{1}'.", environment.Name, lifecycle.Name);
targets.Remove(environment.Id);
}
It appears to simply not work, but maybe I’m missing something. I am using the latest version of Octopus.Client: 3.3.8.0 and my Octopus server is at 3.3.6.