Powershell variable substitution in Octopus variables

I have a script step which calls a ps script inside a package, passing an Octopus variable (connection string) as a parameter. If the Octopus variable contains a $, then the value that the script receives is wrong: 123$qwe becomes 123. If I set the variable to 123`$qwe (powershell-escape the $) then it works, but I need to use the variable as a replacement in a file, and there the backquote is in the way. One (ugly) solution I see is to define two variables, one with and one without the backquote.

Is there a way to pass the variable to the script without $xxx being interpolated?

Thanks,
Victor

Hi Victor,

Thanks for getting in touch! Unfortunately you’re running in to a bug in the way we hand your parameters to your script. I’ve raised an issue on our bug tracker at GitHub here that you can keep an eye on. Even once this is fixed it will be a bit of a pain to do what you are doing, you will need to set your parameter in Octopus using something like -connectionString ''#{ConnectionString}'', note the double single quotes.

As a workaround, and perhaps more simply, we do variable substitution on your script file before we execute it, so you should be able to add something like:

$connectionString = '#{ConnectionString}'

at the top of your powershell file, rather than handing the value in as a parameter.

Hope that helps!

Mark

Hi Mark,

Thanks for your answer! I’ll keep an eye on the bug.

Notice:

This issue has been closed due to inactivity. If you encounter the same or a similar issue and require help, please open a new discussion (if we asked for logs or extra details in this thread, consider including them in the new thread). If you are the creator of this thread and believe it should not be closed let us know via our support email.