Initially we had only non-tenanted deployments and got many environments deployed that way. Now our deployment process become more complex and we do tenanted deployments ONLY. The problem is that old non-tenanted deployments are still everywhere, from Octopus dashboards to Tentacle Release and File caches. How do we remove them once and for all? I understand Tentacle retention policy is only applied to the artifacts of the same deployment type, so as we no longer do un-tenanted deployments - those massive caches related to them are going to stay forever! Dashboards also look polluted with this old and not relevant anymore stuff.
Thanks for getting in touch! I’m glad to see you are moving towards
Tenanted deployments only mode - it removes a bunch of complexity.
But I fear you have uncovered a missing piece of the puzzle. We generally consider the “mixed mode” of untenanted/tenanted deployments as a bridge from one model to the other. The 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.
I’ve raised this GitHub Issue to provide this kind of feature: https://github.com/OctopusDeploy/Issues/issues/3169
In the meantime you can safely run a SQL script like this to clean up the Deployment-related records from your database for your project, which should also clean up your dashboards:
DELETE FROM DeploymentHistory WHERE ProjectId = 'Projects-MyProjectId' AND TenantId IS NULL
DELETE FROM DeploymentRelatedMachine WHERE DeploymentId NOT IN (SELECT Id FROM DeploymentHistory)
DELETE FROM VariableSet WHERE IsFrozen = 1 AND OwnerId NOT IN (SELECT Id FROM DeploymentHistory)
Note you will need to replace the
Projects-MyProjectId with the real project Id from the database.
Hope that helps!
Thank you, Mike!
First and third SQL statements you provided worked. But second statement failed with
Msg 245, Level 16, State 1, Line 2
Conversion failed when converting the nvarchar value ‘Deployments-1001’ to data type int.
Whoops! That was my fault. I’ve since changed the workaround to a C# script since it will be more compatible with all versions of Octopus.
To keep moving forwards you should run the C# script described here: https://github.com/OctopusDeploy/Issues/issues/3169
If that doesn’t work as expected this is the equivalent SQL script you can run (but I prefer the C# script):
DELETE FROM Deployment WHERE ProjectId = 'Projects-MyProjectId' AND TenantId IS NULL
DELETE FROM DeploymentRelatedMachine WHERE DeploymentId NOT IN (SELECT Id FROM Deployment)
DELETE FROM VariableSet WHERE OwnerId LIKE 'Deployment-%' AND IsFrozen = 1 AND OwnerId NOT IN (SELECT Id FROM Deployment)
Once you run either script in entirety you should notice the Project Overview doesn’t have the Untenanted row, which may require a browser refresh, and your database should have no recollection of those Deployments apart from the Audit Log. The task for the Deployment(s) are cleaned up by another process.
Hope that helps!