Get NuGet package directory path

To get the directory path where my NuGet package is deployed, I can use the #{Octopus.Action[_name_].Output.Package.InstallationDirectoryPath} variable where _name_ is my NuGet package deployment step name.

I would like to abstract this away in my script module. The following does not work but would it be possible to get the above without knowing the step name. So below I have the step name variable inside the directory path variable:

#{Octopus.Action[#{Octopus.Step.Name}].Output.Package.InstallationDirectoryPath}

Hi!

Thanks for getting in touch. I’m glad you’re exploring some more advanced scenarios in Octopus, output variables are very useful. In this case you need to be aware the Octopus.Action[_name_].Output.Package.InstallationDirectoryPath variable won’t be available until after the Package Step has completed. The Output Variables are written to the log in a special format that is read by the Octopus Server after the step completes, and that variable is made available to the subsequent steps. I wonder if this is contributing to the problem?

The easiest way to debug these situations is to use some special variables that will make Octopus print the variables into your task log: http://docs.octopusdeploy.com/display/OD/Debug+problems+with+Octopus+variables

I hope this helps, but if I’m misunderstanding your situation please feel free to get back in touch!
Mike

I am aware of that fact. When I use Octopus.Action[_name_].Output.Package.InstallationDirectoryPath on it’s own it resolves correctly. I am also aware of the debug variables and am already using them.

My question is, how can I get the InstallationDirectoryPath for the current step without knowing the step name. My use case is that I want to use this variable in a script module where you don’t know the step name.

Hi!

Thanks for getting back to me. It sounds like you’re quite comfortable with some of these advanced Octopus concepts then.

You could try using an internal Calamari variable that is set after the Package is extracted, which isn’t indexed by step-name: [Package.InstallationDirectoryPath](https://github.com/OctopusDeploy/Calamari/blob/master/source/Calamari/Deployment/SpecialVariables.cs#L101)

Take a look at the Calamari code that does the package extraction which sets this variable: https://github.com/OctopusDeploy/Calamari/blob/master/source/Calamari/Deployment/Conventions/ExtractPackageConvention.cs#L30

I did a sample on our Demo server with this script in the Deploy.ps1

$instPath = $OctopusParameters["Package.InstallationDirectoryPath"]
Write-Output "Installation Path: $instPath"

This printed the expected folder path.

Hope that helps!
Mike