Cannot use custom script with variables


I have a deployment that need to update a database. I have configured the connectionString as a secure variable. I have enabled custom scripts and in the post-deploy script I have this:

$file = $OctopusParameters['Octopus.Action.Package.InstallationDirectoryPath'] + "\Db.exe"

& $file '$ConnectionString'

This does not work.
First the log shows that “$upgradeFile” = “”\Db.exe". Which means that the parameter is empty.
Second (if I hardcode that path), I see that the input to my file is “$ConnectionString”. Which means that it is not replaced.

So the parameter is empty - but the variable is not changed. Any ideas?

I could choose to have the connectionString substituted in a file - this works but it would then mean that the connectionString (with passwords) are stored in text on the deployment. I don’t want that.

Is my approach the recommend way of doing this stuff (passing the connectionString as a parameter in script)? Or do I have another more secure (out-of-the-box) option?


I think there is just a little confusion on the variable name. If you are executing this within the deployment step itself then the variable name is actually just $OctopusParameters["Package.InstallationDirectoryPath"]. Notice the missing Octopus.Action.
Alternatively if you are trying access this value from a subsequent step you can use $OctopusParameters["Octopus.Action[StepName].Output.Package.InstallationDirectoryPath"] (note this output variable can be also be used in the original step itself).

Secondly in PowerShell if you place a string inside single quotation marks (’) then PS wont evaluate the variables contained within the expression. Instead you can either remove them entirely, or replace them with double quotes. Let me know if that still causes a problem.

Thanks for clarification and the PS assistance. It all works now!

However I can’t say that I understand the logic about parameters/variables when comparing to the documentation about system variables. Looking at the help I got in the thread below, it is not clear when to use what (the link suggest to use ‘Octopus.Action.Package.InstallationDirectoryPath’ within the step.

Should I be able to guess the parameter constants? Maybe it is just me :slight_smile:


Hi Itemplate,
I have added the suggestion as GitHub Issue #2300 as I tend to agree with you.
Thanks again for your input.

Excellent, again, thanks for helping out…