Custom variable values not passed to PowerShell script

I am trying to pass custom variables from Octopus into a PostDeploy.ps1 file as described in the Variables section on the PowerShell Scripts page. I have my variables defined as shown in the attached screenshot. When I run my deploy script, however, it doesn’t look like the values are being passed to the PowerShell script. I get output similar to the snippet below (full output and PowerShell script also attached)…

@@@
2013-02-19 17:06:36 DEBUG Looking for PowerShell scripts named PostDeploy.ps1
2013-02-19 17:06:36 INFO Calling PowerShell script: ‘C:\Octopus\Applications\Development\WebSearchContent\1.0.4.84_1\PostDeploy.ps1’
2013-02-19 17:06:42 INFO PostDeploy.ps1: Now running
2013-02-19 17:06:42 INFO ReplaceTheme_TargetThemeName=
2013-02-19 17:06:42 INFO ReplaceTheme_SourceThemeName=
2013-02-19 17:06:42 INFO OctopusEnvironmentName= Development
2013-02-19 17:06:42 INFO OctopusOriginalPackageDirectoryPath= C:\Octopus\Applications\Development\WebSearchContent\1.0.4.84_1
2013-02-19 17:06:42 INFO PostDeploy.ps1: Overwriting ’ ’ theme with ‘’ theme…
2013-02-19 17:06:45 INFO PostDeploy.ps1: Finished overwriting ’ ’ theme with ‘’ theme…
2013-02-19 17:06:45 INFO PostDeploy.ps1: Stopping
2013-02-19 17:06:45 DEBUG Script ‘C:\Octopus\Applications\Development\WebSearchContent\1.0.4.84_1\PostDeploy.ps1’ completed with return code 0.
@@@

I notice that the example variable name on the PowerShell Scripts page is named MyApp.ConnectionString. Does the MyApp part indicate a project name (maybe I need to name my variables ProjectName.ReplaceTheme_SourceThemeName and ProjectName.ReplaceTheme_TargetThemeName)?

-David

DeployLog.txt (4 KB)

PostDeploy.ps1.txt (2 KB)

Hi,

When we pass variables to PowerShell, we change some of the names to ensure they are valid powershell identifiers. For example, if your variable was named:

The_Cat Sat On The###Mat

We’d pass it as:

$TheCatSatOnTheMat

We currently do it by stripping anything that isn’t a number or a letter.

We also pass the variables as a dictionary without modifying, so you could access it as:

$OctopusParameters["The_Cat Sat On The###Mat"]

Now some of that replacement makes sense - a PowerShell variable can’t have “.” in the name for example. But thinking about it, “_” is perfectly valid in a PowerShell identifier. So there’s no reason to not include underscores in the name.

My apologies for this as I’m sure you’ve wasted a lot of time on what is a silly bug on our part. I’ll make sure we fix it in a future release.

For now, using either “$OctopusParameters[…]” or using the variable without the underscore will fix it. I’ll make sure that when we do fix the bug, we provide both variables just in case people depend on this behavior.

Sorry once again,

Paul

No problem, Paul. Your workaround works just fine. Thanks for the help.