Last active
August 16, 2016 20:06
-
-
Save Dalmirog-zz/be27be0c83618734e424 to your computer and use it in GitHub Desktop.
Delete all deploments for a Project-Environment
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
$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