Find if a release has been created or not Via API

I have a situation where I have two octopus servers one for my production instance and one for my non production instance. In this situation I have times in which I must verify if i need to create a release to match what is in the other environment. What I’d like to know is if there is a api call that is similar to api/dashboard to find releases based on versions for specific projects.

Here is a function I’ve written to retrieve all releases from an octopus server. This takes several minutes to retrieve the entire set so it can then be searched in memory where the query was executed.

function get-releases($server, $apikey)
{
$projects = @()
$proj = Connect-to-Octopus $server $apiKey ‘api/releases’
$projects += $proj |Select-Object -ExpandProperty Items
for($i = 30; $i -lt ($proj.totalresults) ;$i+=30)
{
$nextProj = ($proj.Links.‘Page.Next’)
If ($nextProj -ne $null)
{
$proj = Connect-to-Octopus $server $apiKey $nextProj
$projects += $proj | Select-Object -ExpandProperty Items
}
}
return $projects
}

function Connect-to-Octopus
([Parameter(Mandatory=$true)]
[string] $server,
[Parameter(Mandatory=$true)]
[string] $apikey,
[Parameter(Mandatory=$true)]
[string] $uri)
{
$fulluri = “http://$server/$uri
$result = invoke-restMethod -uri $fulluri -Method Get -Headers @{‘X-Octopus-ApiKey’=$apiKey}
return $result
}

Hi Thom,

Thanks for getting in touch! https://github.com/OctopusDeploy/OctopusDeploy-Api/wiki/Projects
The bottom example shows how to grab releases based on projects and versions.

Hope that helps!
Vanessa

ok that helps… but i have ton of releases. Is this api query sorted by the lastdeployment?

After digging into the api a bit try looking at this one:

https://myoctopusdeploy.corp/api/projects/pulse?projectIds=[SOME-PROJECT-ID]

The docs on this are not filled out all the way but what I’m seeing is this:

[
{
Id: “pulse-projects-22”,
ProjectId: “projects-22”,
MostSignificantDeploymentId: “deployments-4414”,
EnvironmentId: “Environments-4”,
EnvironmentName: “Production”,
Deployed: “2015-01-08T15:36:23.456+00:00”,
Links: { }
}
]

That is the latest deployment for that project. Note that it’s just the last deployment across all environments. So if the last deployment was to development then you get just that one.

If you want to get the latest deployment for each environment then I would use the /api/dashboard call:

That gets you all the projects visible to that user on their dashboard, the environments and the latest deployments. It’s the json view of what you see when you view the dashboard in Octopus. The deployments are in the ‘Items’ property of that JSON payload.

I’ll be out on vacation 2-19 - 2-23.

Well, I got ahead of myself. Only responded to your question about latest deployment. And then I read the original question which you already know about the dashboard call.

Hi Thom & David,

I’ve been working on a powershell module that will help users getting info such as the one you are looking for, among other stuff.

There’s a cmdlet called Get-octopusRelease on the module that gets info about the current releases which let’s you filter by Project and Release Number. I think that is what you are looking for if I’m not mistaken.

I could really use some testers for these cmdlets if you guys are up to the task :slight_smile: . Comments on what cmdlets you’d like in the future would also be great.

Please keep in mind that this is an open project at the moment, and it’s not officially supported by Octopus even though it’s being developed by one of their staff members. All questions about it must be made on the github project and not on this forum.

Thanks!

Dalmiro