Vagif Abilov
Vagif Abilov

Reputation: 9991

Invoking a command with variable evaluation in Octopus Deploy Powershell script

I have a simple Powershell script that I execute during an Octopus Deploy installation. This line works fine:

& $exe install --autostart

I runs an application identified by $exe variable with command line arguments "install --autostart".

Now I need to expand command line arguments with a value evaluated from a variable:

& $exe install --autostart -servicename=$serviceName

"$serviceName" is the variable that gets its value during the script execution. Whatever I do it's passed to the line above by variable name, not the value, e.g. it's passed as "$serviceName". I tried single and double quotes, nothing helps. As long it's a command invocation (triggered by the "&" symbol in the beginnging of the line), the rest of the line is interpreted verbatim, no variable substitions.

I used last couple of hours trying to figure this out and this is driving me mad. Any tips are appreciated.

Upvotes: 0

Views: 485

Answers (1)

Mike Garuccio
Mike Garuccio

Reputation: 2718

I just did some testing on my side and it looks like if you'd like the variable passed in to the command to be evaluated as a variable it needs whitespace on both sides. So you would want to define your variable as $serviceName = "-servicename=*name*" or if that is not possible then create a new variable just before running the command

$tmpServicename = "-servicename=$($serviceName)"
& $exe install --autostart $tmpServiceName

Upvotes: 1

Related Questions