API: get package name associated with release or project

Hi,

I want to get a name of package that was associated with release or project.

$releases = (Invoke-WebRequest $OctopusURL/api/projects/$projectId/releases -Headers $header).Content | ConvertFrom-Json
$package = $releases.Items[0].SelectedPackages[0].StepName

For some projects it returns the name of package for some projects it returns “Deploy”. SelectedPackages only have StepName and Version fields.
Are there any other methods to get a name of package associated with release. Or is there method to get package name from deployment process of project(from deployment step for example)?
I tried this:

$project = (Invoke-WebRequest $OctopusURL/api/projects/Projects-37 -Headers $header).Content | ConvertFrom-Json
$depId = $project.DeploymentProcessId

$deploy = (Invoke-WebRequest $OctopusURL/api/deploymentprocesses/$depId -Headers $header).Content | ConvertFrom-Json

foreach($step in $deploy.Steps)
{
    foreach($action in $step.Actions)
    {
        if($action.ActionType -eq 'Octopus.TentaclePackage')
        {
            $action.Properties.'Octopus.Action.Package.NuGetPackageId'
        }
    }
}

but it returns string “#{packageID}”

Hi Viktor,

Thanks for reaching out. You might wanna take a look at the Octoposh project, which has a couple of useful Powershel cmdlets to get info like the one you are asking for.

In this case you could use the cmdlet Get-OctopusDeployment which will return an object that looks like the one on the attached screenshot for each deployment. One of its properties contains all the packages used in that deployment.

Project URL: http://Octoposh.net
Cmdlet wiki: https://github.com/Dalmirog/OctoPosh/wiki/Get-OctopusDeployment

Hope that helps,
Dalmiro

If you don’t want to use that module and want to build your own code, you can check that cmdlets code on the project: https://github.com/Dalmirog/OctoPosh/blob/master/Scripts/Get-OctopusDeployment.ps1

Hi Dalmiro,

Looks like Get-OctopusDeployment cmdlet uses the same logic that I used. And it returns the same:

ProjectName : *********
EnvironmentName : *********
DeploymentstartTime : 23.12.2015 10:26:03
DeploymentEndTime : 23.12.2015 10:26:38
DeploymentStartedBy : *****************
ID : Deployments-930
Duration : 0,58
Status : Success
ReleaseVersion : 12.6.30
ReleaseCreationDate : 21.12.2015 18:28:45
ReleaseNotes :
ReleaseCreatedBy : *****************
Package : {@{Name=#{packageID}; Version=12.6.30}}
Resource : Octopus.Client.Model.DeploymentResource

We use Octopus 3.2.15. Maybe there was some bugs in this Octopus version? Also we use external nuget feed to store packages. We don’t use build-in Octopus feed.

Are you using the variable #{packageID} to define the Package ID on your Nuget deploy step?

Yes. Now I see there is a problem.

That’s right - When you send the POST request to create a deployment, you are creating a document/db entry with the Package ID #{PackageID}. This is what both your script and the Octoposh cmdlet are retrieving.

During the deployment that variable gets resolved, but the resolved Package ID is not updated on the deployment doc.

Unfortunately there’s no way to programatically retrieve the package ID if you’re using a variable to declare it.

Sorry for the crappy news
Dalmiro