Using the API to retrieve a list of recently failed deploys

Hello,

I understand using something like this:
https://myOctoupsUrl/api/deployments?taskState=failed

will retrieve a list of failed deployments. We have a huge number of deploys and I’m hoping I can do something like:

  1. Get the most recent deployment failures
    or
  2. Get the list of deployments that recently failed (were successful before)

Additional details that would be helpful would be details like who triggered the deploy.

I’ve been digging through documentation and navigating through the /api tree in the browser but can’t find a solution.

Is there one available?

Hi Tobin,

Thanks for reaching out!

The /deployments api doesn’t have a filter for date, but it has take which allows you to decide how many deployments to want to retrieve.

As for getting the name of the user who triggered the deployment, that info will be on the Event related to that deployment.

I’d recommend you to take a look at Octoposh which has a cmdlet called Get-OctopusDeployment that could help you here.

The cmdlet has a -before and -after filter that you can use to decide how far back in time you want to fetch deployments. While it doesn’t have a filter for “status”, the object it returns does have a Status property that you can filter once you have the deployments in memory. The below example shows how the object returned by this cmdlet looks like:

ProjectName         : Files
EnvironmentName     : Dev
DeploymentStartTime : 05/05/2017 1:21:39 PM
DeploymentEndTime   : 05/05/2017 1:22:10 PM
DeploymentStartedBy : dalmiro.granias@NY.local
Id                  : Deployments-3724
Duration            : 00:00:31
Status              : Success
ReleaseVersion      : 2.0.16
ReleaseCreationDate : 05/05/2017 1:21:36 PM
ReleaseNotes        :
ReleaseCreatedBy    : dalmiro.granias@NY.local
Packages            : {TestPush}
Resource            : Octopus.Client.Model.DeploymentResource

You’ll notice that It also shows who created the release and the deployment.

You can find the doc for that cmdlet over here: http://octoposh.readthedocs.io/en/latest/cmdlets/get-octopusdeployment/

Let me know if that helps,
Dalmiro

Thank you for the quick reply Dalmiro. We have a massive amount of
deployments (in the thousands). We are automating the build and tear down
of many environments, platforms and deployments.

I looked at Octoposh and the source and appreciate what is being done
there. I can get to what I need by processing these most likely, but
there will be a lot of noise.

In CI/CD scenarios, designers of the system very much want to see
deployments that WERE working and are recently broken so that we can halt
the pipeline and get the responsible party to fix it.

TeamCity has a neat solution for it in their API:
https://myTeamCityURL/httpAuth/app/rest/builds/?locator=status:failure,sinceBuild:(status:success)

This way you can get to a “clean” state and then turn on monitoring like
this to keep the CI/CD pipeline clean.

Ideally, I would love to see something like a “previousState” parameter in
the deployments API template like this:

https://myOctopusDeployURL/api/deployments?taskState=failed,previousState=success

I think it is justified because many large deployment pipelines will have
many failures, but there are only certain ones you care about.

image001.png

Hi Tobin,

I can see how that feature would come in handy. Is there any chance you can submit that idea in Uservoice? If enough users in the community back that idea, we could definitely consider it for future updates.

https://octopusdeploy.uservoice.com/

For the time being in the current state of our API, I’m afraid the above suggestion is the only one available.

Thanks,
Dalmiro