Last active
September 2, 2016 06:19
-
-
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
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
$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