Unable to get Nuget package name in Powershell script as a variable


I’d like to retrieve the nugget package name that was used for the deployment in a powershell script at a later stage of the deployment process.

I’ve tried $OctopusParameters[“Octopus.Action.Package.NuGetPackageId”] and even $OctopusParameters[“Octopus.Action[Deploy To Azure].Package.NuGetPackageId”] where Deploy to Azure is the name of the step but it doesn’t work…

Can anyone help me with this?

Thank you!

I have found this wiki here: https://github.com/OctopusDeploy/Issues/wiki/Migrating-from-Octopus-Deploy-1.x

It says that migrating from 1.6 to 2.0:
OctopusPackageName became Octopus.Action.Package.NuGetPackageId and also to Omit full-stops/periods when using as PowerShell variables

So, effectively is my variable really: $OctopusActionPackageNuGetPackageId ??

The Octopus.Action.Package.NuGetpackageId and $OctopusActionPackageNuGetPackageId forms only work from the step that package is deployed in. For later steps you will need to include the name of the step.

Note that in the current version that variable is only available if the step ‘Deploy to Azure’ has run. If “Skip packages that are already installed” is set for that project and the step is skipped the variable will be undefined. There is a recently closed issue on github that should change this behaviour in 2.5.3.

Even though both the documentation and the blog post Fun With Input Variables use double quotes I’ve always been more succesful with single quotes. Try:
$OctopusParameters['Octopus.Action[Deploy To Azure].Package.NuGetPackageId']

That dictionary variable also interacts weirdly with other PowerShell bits occasionally. I usually do something like $AzurePackageId = $OctopusParameters['Octopus.Action[Deploy To Azure].Package.NuGetPackageId'] at the beginning of my script. It’s a lot easier to embed the variable $AzurePackageId in a string or pass it to a function. I’ve found that setting up short, friendly names for all the $OctopusParameters[] variables I use saves a lot of grief.

Thank you! It works :slight_smile: