Skip to content

Instantly share code, notes, and snippets.

@Dalmirog-zz
Last active August 16, 2016 20:06
Show Gist options
  • Save Dalmirog-zz/be27be0c83618734e424 to your computer and use it in GitHub Desktop.
Save Dalmirog-zz/be27be0c83618734e424 to your computer and use it in GitHub Desktop.
Delete all deploments for a Project-Environment
$apiKey = "Your API Key"
$OctopusURL = "Your Octopus URL"
$Header = @{ "X-Octopus-ApiKey" = $apiKey }
$ProjectName = "Your project name"
$EnvironmentName = "Your environment name"
#Getting Environment and Project By Name
$Project = Invoke-WebRequest -Uri "$OctopusURL/api/projects/$ProjectName" -Headers $Header| ConvertFrom-Json
$Environment = Invoke-WebRequest -Uri "$OctopusURL/api/Environments/all" -Headers $Header| ConvertFrom-Json
$Environment = $Environment | ?{$_.name -eq $EnvironmentName}
#Getting all deployents for Project-Environment combination
$deployments = Invoke-WebRequest -Uri "$OctopusURL/api/deployments?projects=$($Project.id)&environments=$($environment.id)" -Headers $Header | ConvertFrom-Json
#Deleting all the deployments one by one
foreach ($deployment in $deployments.Items){
Invoke-WebRequest -uri ("$env:OctopusURL" + $deployment.Links.Self) -Headers $Header -Method Delete
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment