How to update the deployment state in Octopus

The issue

There is now the ability to change the state of a deployment after its happened.
This can be useful if there are scenarios where external apps can remove deployments triggered from Octopus, and you want a way to let Octopus know that an app is no longer there.
A good example of this is BizTalk deployments where an app getting deployed will remove other applications that are dependant on it.

Process

Get the Server-Task Id from the Deployment record
then run the following (obviously alter it a bit based on your needs) :
1
$apikey = 'APIHFHFHFHFHFHFHFHFH'
2
$header = @{"X-Octopus-ApiKey"=$apikey}
3
4
$serverTaskId = 'ServerTasks-1638'
5
$octopusUri = "https://$instanceName.octopus.com/api/tasks/$serverTaskId/state"
6
7
$data = @{state='Failed'; reason='Application was removed as part of installation of Contoso.Schemas.'}
8
$body = $data | ConvertTo-Json
9
10
Invoke-RestMethod -Method Post -Uri $octopusUri -Body $body -Headers $header
Copied!
This will update the status. Example shown below:
Sample Octopus Projects
Copy link