Skip to content

Instantly share code, notes, and snippets.

@hnrkndrssn
Last active September 2, 2016 06:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hnrkndrssn/e99bd41d2a0f7250f905a9e91999990a to your computer and use it in GitHub Desktop.
Save hnrkndrssn/e99bd41d2a0f7250f905a9e91999990a to your computer and use it in GitHub Desktop.
Manual retention policy when a variable has been used for the package to be deployed
$deploymentJournalPath = Get-Item $env:TentacleJournal
if($deploymentJournalPath) {
$itemsToKeep = $null
$useItemsToKeep = [System.Int32]::TryParse($OctopusParameters["OctopusRetentionPolicyItemsToKeep"], [ref]$itemsToKeep)
if(-not $useItemsToKeep) {
Write-Host "Could not find the number of deployments to keep, ensure the lifecycle is set to keep a limited number of releases"
return
}
$projectId = $OctopusParameters["Octopus.Project.Id"]
[xml]$deploymentJournal = Get-Content $deploymentJournalPath.FullName
$deployments = $deploymentJournal.Deployments.Deployment `
| ? { $_.ProjectId -eq $projectId } `
| Sort-Object InstalledOn -Descending `
| Select-Object -Skip $itemsToKeep `
| % {
if(Test-Path $_.ExtractedTo) {
Write-Host "$($_.ExtractedTo) will be removed"
# Remove-Item -Path $_.ExtractedTo -Recurse -Force -Verbose
}
if(Test-Path $_.ExtractedFrom) {
Write-Host "$($_.ExtractedFrom) will be removed"
# Remove-Item -Path $_.ExtractedFrom -Force -Verbose
}
}
} else {
Write-Host "Could not find 'DeploymentJournal.xml'"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment