Rest api - delete orphaned releases

How do I use the rest api of octopus to find all releases with no nuget packages and delete them

Hi Michael,

Thanks for reaching out. You can do it like this:

  1. Loop thorugh all the pages of /api/releases and gather all the realeases that have "SelectedPackages": []

  2. Foreach release found in (1), do a DELETE rest call to the full url of the release (i.e. /api/releases/Releases-4505)

Hope that helps!
Dalmiro

That doesn’t work for me. Our nuget packages have a retention policy set so when the release was created the nuget package existed. But today it does not. How do I find out from octoous which release no longer have nuget packages to cleanup the orphaned releases?

HI Michael,

Please let me know if I got this straight, just to make sure we are on the same page: You are saying that you have releases that were using a certain package. Then those packages were deleted by the retention policy, but the releases were not. And you are now trying to delete these orphaned releases?

Do you have a retention policy in place for your releases on your lifecycle? Because that’ll be the right way to programatically get rid of old releases. In case you don’t know what I’m talking about, there’s more info about this over here: http://docs.octopusdeploy.com/display/OD/Retention+Policies

Regards,
Dalmiro

I understand octopus has a retention policy but it is VERY limited. For Example our nuget retention policy is

Delete all nuget packages that have never been downloaded/deployed and are older than 30 days.

Octopus does not provide any retention policy to mirror this. Therefore i would like to do more advanced retention policy mechanics using the octopus rest api…but it looks like this is not possible.

Hi Michael,

I’d like to give you a hand with this retention policy you are trying to set :). But for this I need to fully understand in which cases you’d like to delete the releases.

Initially you said that you wanted to “delete all releases with no Nuget packages”. It seems I misunderstood what you meant, reason why I asked again but this time using a scenario as an example.

Is there any chance you can walk me trough this in a similar fashion (with an example) so I can understand which releases you are trying to delete?

Best regards,
Dalmiro

Okay so lets start over. We have a Retention policy setup in our proget nuget feed like so

1.) Delete all nuget that are older than 30 days and have never been downloaded ( this technically means downloaded by a nuget restore in visual studio OR downloaded by octopus in order to perform a deployment! )

Therefore once this retention policy runs we have releases in octopus that were created when the nuget packages existed but now no longer exist due to our retention policy ( and have never been deployed/downloaded by octopus ). There are are a couple of strategies to go about this but the below seems the easiest which is what i want to do.

Strategy 1. Simply delete all octopus releases that no longer have a nuget package associated with it

I’m having trouble figuring out how do to Strategy 1.

Hi Michael,

Thanks for taking the time to walk me trough this more in depth :).

The below C# code will find all the releases that are tied to a package (whether the package still exists or not). It’ll create a list called inUsePackages which will have objects that’ll have the properties:

  • Release ID
  • The full Release objects (which you can use to delete it afterwards)
  • Package ID
  • Package Version

Once you have that list, you can match it with the existing package in Proget and then delete the orphaned releases.

Let me know if that works for you.

Thanks!
Dalmiro