Remove a deployment on the dashboard

Hello,

I have a few deployments on my dashboard that were showing as ‘Failed’. I was able to use the following script to modify the status from ‘Failed’ to ‘Cancelled’

$apikey = 'APIHFHFHFHFHFHFHFHFH'
$header = @{"X-Octopus-ApiKey"=$apikey}
$serverTaskId = 'ServerTasks-1638'
$octopusUri = "https://$instanceName.octopus.com/api/tasks/$serverTaskId/state"
$data = @{state='Failed'; reason='Application was removed as part of installation of Contoso.Schemas.'}
$body = $data | ConvertTo-Json
Invoke-RestMethod -Method Post -Uri $octopusUri -Body $body -Headers $header

I’d those deployments to not show at all anymore on my dashboard. Is there anyway to do that?

For example, instead of having 1.0.2 for Contoso.Customer under Test. I want it to be empty

Hi,

Thanks for reaching out.

There actually is an API call you can utilize to clear out that deployment. You can do a DELETE on a deployment endpoint. To get the deployment ID to run the DELETE on, you would go to the release in the api, then find the desired environment in the JSON to get the ID, then run the delete on that ID.

To get a list of API calls available to you, you can always check out SwaggerUI by going to https://youroctopusurl/swaggerui.

For example: Invoke-RestMethod -Method DELETE -Uri "https://192.168.139.160/api/deployments/Deployments-1386" -Headers @{"X-Octopus-ApiKey" = "API-####" }

Please let me know if that works for you or if you have any other questions.

Best,
Jeremy

1 Like

Thank you, this worked

1 Like

You’re very welcome! Thanks for letting me know you got it working.

Please let us know if you have any other questions in the future.

I hope you have a great rest of your week.

Best,
Jeremy