Script to delete 2.6 deployed files after a 3.0 upgrade
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
withGet-ChildItem -Path $_.ExtractedTo -Recurse
and the script will output the files / folders that would be removed.