Fetch deployment target from deployed release

Hi Guys,

I would like to know if there is a way to pull what machines a deployment was deployed to using the client API?

I have been tasked to find the latest release of a project and see what machines the deployment went too.

All I was supplied is a project name. I managed to find the details inside the raw logs. Is that the only way?

I started with these steps

Finding releases for the project.
Once I have the releases I then match the deployments of that release
Then I get the raw logs.

In the database I see things like “Deployed to environment” but nothing machine specific.

I am trying to achieve this all without looking at the UI at all. Is it possible and if so could you point me in the right powershell direction.

Thanks,
Lance

Hi Lance,

Thanks for getting in touch. You are correct that we don’t store machine details for a deployment. Environments are the core concept as machines can come and go. The following help thread does discuss the best option to retrieve machine details from a deployment.
http://help.octopusdeploy.com/discussions/questions/5624-machine-names-involved-in-deployment-through-api

The code examples in the link above use C# and the Octopus.Client NuGet package but the interaction is very similar with Powershell. The following links should help you get up and running.

Hope this helps!

Rob

Hi,

Anyone smart enough to help me convert it to powershell?

http://help.octopusdeploy.com/discussions/questions/5624-machine-names-involved-in-deployment-through-api

Thanks,
Lance

Hi Lance,

The scripts aren’t terribly different. I don’t know if you’ve had a look at the linked blog post but it gets you up to speed with the using Octopus client library from powershell and the other help thread provides the steps needed to get the data you need.

Let me know how you go.

Rob

Hi,

I know how to use the client library to do some stuff. Get environments,machines and releases etc. I just haven’t used this before.

Octopus.Client.Model.DashboardResource and Octopus.Client.Model.DashboardItemResource

Help would be appreciated.

Hi Lance

I’m working on a simple example of this. I’ll follow-up when it’s finished.

Thanks

Rob

Hi Rob,

I seem to have come right with this one. Here is how you get the machines that a project has been deployed too.

$endpoint = new-object Octopus.Client.OctopusServerEndpoint $OctopusURL,$OctopusAPIKey;
$repository = new-object Octopus.Client.OctopusRepository $endpoint;
$project = $repository.Projects.FindByName(“PROJECTNAME”)
$environment = $repository.Environments.FindByName(“ENVIRONMENT”);
$env = $environment.Id
$pro = $project.Id
$queryString = “?environments=$env&projects=$pro”
$url = “/api/dashboard/dynamic$queryString”
$result = Invoke-RestMethod -Uri “$OctopusURL$url” -ContentType application/json -Headers @{“X-Octopus-ApiKey”="$OctopusAPIKey"} -Method Get -Verbose
$task = $repository.Tasks.Get($result.Items[0].TaskId)
$taskdetail = $repository.Tasks.GetDetails($task)
$finaldetails = $taskdetail.ActivityLog.Children
$finaldetails.Children.Name | select -Unique
$finaldetails.Children.Status | select -Unique

Thanks,
Lance

Hi Lance,

Thanks for following up! I was trying to do it with the Octopus Client nuget package but I hit some roadblocks and I was going to revisit it with the restful API. Your solution is excellent! Thanks for sharing!

Rob