Skip to content

Instantly share code, notes, and snippets.

@vanessalove
Created September 1, 2015 03:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vanessalove/dbc656b01df40939dcf8 to your computer and use it in GitHub Desktop.
Save vanessalove/dbc656b01df40939dcf8 to your computer and use it in GitHub Desktop.
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"
}
@vanessalove
Copy link
Author

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