Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a first-class way to delete untenanted deployments when changing Project to tenanted-only mode #3169

Open
michaelnoonan opened this issue Feb 13, 2017 · 3 comments

Comments

@michaelnoonan
Copy link
Contributor

@michaelnoonan michaelnoonan commented Feb 13, 2017

We generally consider the "mixed mode" of untenanted/tenanted deployments as a bridge from one model to the other. One missing piece here is that we don't provide a first-class way to clean up the untenanted deployments when changing to Tenanted deployments only mode. The result is that the untenanted deployments never get superseded, meaning they stay on the dashboard forever, and retention policies can do nothing about cleaning them up.

Suggested Solution

When the Project's multi-tenant deployment mode changes to Tenanted deployments only we could prompt the user to see if they want us to delete all of the untenanted deployment history for that project. If not, we leave the history alone. If yes, we delete all the deployment history and related documents via cascade rules.

Workaround

Until we add this enhancement you can safely use C# (or PowerShell) script like this one to achieve the same result:

void Main()
{
	string octopusUrl = "http://localhost:8065";
	string apiKey = "API-XXXXXXXXXXXXXXXXXXXXXXXXXXX";
	string projectName = "myprojectname";

	var octopusServer = new OctopusServerEndpoint(octopusUrl, apiKey);
	var repo = new OctopusRepository(octopusServer);

	var project = repo.Projects.FindByName(projectName);
	if (project == null)
		throw new Exception($"There is no project called {projectName}");
	
	var releases = repo.Projects.GetAllReleases(project);
	
	var environments = repo.Environments.GetAll();

	var deletedCount = 0;
	repo.Deployments.Paginate(
		new[] { project.Id },
		environments.Select(env => env.Id).ToArray(),
		(page) =>
		{
			var untenantedDeployments = page.Items.Where(d => string.IsNullOrWhiteSpace(d.TenantId));
			foreach (var untenantedDeployment in untenantedDeployments)
			{
				deletedCount++;
				var url = untenantedDeployment.Link("self");
				Console.WriteLine($"Deleting {url} [{untenantedDeployment.Name} {releases.SingleOrDefault(r => r.Id == untenantedDeployment.ReleaseId)?.Version}]");
				repo.Client.Delete(url);
			}
			return true;
		});

	Console.WriteLine($"Found and deleted {deletedCount} untenanted deployments for {project.Name}");
}

The easiest way to do this immediately is to use LINQPad with this shared script. Alternatively you can copy that code into a small C# program and reference the Octopus.Client NuGet Library.

Note you will need to replace the myprojectname with the real project name.

Original Source

http://help.octopusdeploy.com/discussions/questions/10782
https://octopusdeploy.uservoice.com/forums/170787-general/suggestions/16980910-hide-the-un-tenanted-release-goup

@MJRichardson

This comment has been minimized.

Copy link

@MJRichardson MJRichardson commented Oct 6, 2017

This could possibly be addressed simply by retention-policy.
Once a project has been marked as tenanted-only, all untenanted releases could be removed at the next retention-policy run.

@droyad droyad added area/execution and removed area/scale labels Jan 10, 2018
@droyad droyad added the size/medium label Oct 15, 2018
@droyad

This comment has been minimized.

Copy link
Contributor

@droyad droyad commented May 1, 2019

Also allow the deletion of deployments via the UI

@droyad droyad removed the area/execution label May 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.