Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Script to delete 2.6 deployed files after a 3.0 upgrade
$applicationDirectoryPath = $OctopusParameters["Octopus.Tentacle.Agent.ApplicationDirectoryPath"]
$deploymentJournalPath = Get-ChildItem -Path "$applicationDirectoryPath\.Tentacle" -Filter "DeploymentJournal.xml" -Recurse
if($deploymentJournalPath) {
[xml]$deploymentJournal = Get-Content $deploymentJournalPath.FullName
$deploymentJournal.Deployments.Deployment | % {
if(Test-Path $_.ExtractedTo) {
Write-Host "$($_.ExtractedTo) will be removed"
Remove-Item -Path $_.ExtractedTo -Recurse -Force -Verbose
} else {
Write-Host "$($_.ExctractedTo) has already been removed"
} else {
Write-Host "Could not find 'DeploymentJournal.xml' under $applicationDirectoryPath\.Tentacle"
Copy link

In 3.0 OD changed the path of the DeploymentJournal so 2.6 deployments will not be cleaned up by the retention policy on Tentacles.

We have created this script that will find all pre-3.0 DeploymentJournal.xml files and remove all the extract folders for the deployments that still exist on the Tentacle, this script can be run through the Script Console.

If you wanted to test the script first on a Tentacle (without deleting any folders) to confirm that it won't delete folders that should be kept you can replace Remove-Item -Path $_.ExtractedTo -Recurse -Force -Verbose with Get-ChildItem -Path $_.ExtractedTo -Recurse and the script will output the files / folders that would be removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment