Octopus API Part 2: Return Releases for a Project


In part 1b of this series I shared a function that will return a property of a resource available through the API. It was written in such a way that it is ambiguous enough to return any property for any resource, providing it exists. This “providing” qualifier is not handled in the code. So today we’re going to take our function to the next level by adding some basic error handling to it.

We’re then going to make use of it when we call another function that I’m sharing today: Get-OctopusReleases. This function will return all the releases for a given project. But as you can see from the documentation, the uri requires a project id. This is where the “Get-Property” function is required.

The error handling is straightforward,: before we return the parameter we check that it is not null. If it is null we throw an error that that given function has failed. That way we have a chance of tracking down where the issue is.

With regards to the releases, it is the links and items properties that we are most interested in, as these can be used in further functions to return more pertinent data. But that is for another post!

Leave a Reply

Your email address will not be published. Required fields are marked *