I’m looking to use the api to figure out:
a) what environments a project has been deployed to
b) has there ever been a successful deployment to that environment, and if so, when was it
At this point, I’m looking at the iterating through the deployments api, but that is a bit painful, especially as i dont know if there has ever been a deployment to a specific environment, so I have to page through all results.
I’ve looked at the progression api but i’m not sure exactly how it works. Can you clarify if it will always show the latest succesful release to an environment if one exists?
Thanks for reaching out. Before getting our hands dirty with the API, I wanna bring to your attention an OSS project called Octoposh that might be just what you need. It’s a Powershell module that contains several cmdlets that’ll help you get information from (among other things).
There’s a cmdlet called Get-OctopusDeployment on that module that’ll return plenty of info about deployments. Using this cmdlet you can filter by Project, Environment, date of execution, status, and a couple other things. See the attached screenshot for a very brief example.
At the moment, I’m iterating through the deployments, which is a bit painful, especially in the scenario that there has been no deployments to an environment – I end up paging all the way through.
At the moment, I’m iterating through the deployments, which is a bit painful, especially in the scenario that there has been no deployments to an environment – I end up paging all the way through.
A) what environments a project has been deployed to
You can see this information from the Web portal on the dashboard. To render that site, we do a get to /api/dashboard . Take a few minutes to dig into the results of this API call and you’ll find out what you are looking for.
B) has there ever been a successful deployment to that environment, and if so, when was it
This one is a bit trickier and will require a few more API calls. I’m gonna assume you wan’t the latest successful deployment for an environment.
GET /api/deployments?environments=Environments-1&projects=Projects-101 where environments-21 is the ID of your environments and Projects-101 is the ID of your project.
Te call above will return something similar to this:
As you can see, it is only showing 30 results out of the 40 that exist on database. To get the following set of 30 results, you’re gonna hace to check on the link property for the link called Page.next. The logic should go a bit like this:
Get first 30 results
Check if there’s a Successful deployment in them (the results come sorted by time created descending). If there is one keep it and stop the process
If there wasn’t a successful deployment, check the next 30. Repeat process.
Can you tell me how this compares to using the progression api? It appears that the progression api gives me most of this information as well?
What I’ve implemented so far uses the progression api as a first call, then falls back to the deployments api if it can’t find a successful deployment.
Am I understanding the progression api correctly? Or are there underlying implementation details that mean it doesn’t quite work the way I think it does?
The progression API belongs to older versions of Octopus, and its no longer being used in 3.0 (unless I’m terribly wrong). I’d recommend you to follow the approach I described on my previous reply, as It applies to both 2.x and 3.x versions of Octopus.
I must admit I thought we deprecated that API (haven’t checked on it since 2.6 I think), but i believe we improved it instead somewhere between 2.6 and 3.2.
That one is not going away anytime soon, so feel free to keep using it if its giving you the info you need.
Thanks for the confirmation that its going to stick around.
I’d still like to know a few things though:
Can you clarify if the progression api will always return the latest successful deployment to an environment, if one exists? Or is there some edge case where there has been a successful deployment, but many subsequent failing ones, and it wont return the successful one?
is the missing progression link in the /api response a bug? Or by design? (I’d like to follow RESTful principles and navigate via the links where possible).
Re the progression link – it is already a child of the project. I was assuming that it should be on the root api list, but recently I’ve started to question my assumption.
But… It appears nearly all the other links under projects are also listed under the root api link.
I will leave it with you guys to decide how you want to handle it. Happy to close this call.