I have custom step in Octopus. I set Test parameter on step level, it depend on release variable and is for example #{Path to package}
.
Step template runs this code:
$package = $OctopusParameters[‘Test’]
$cmd = “"C:\Program Files (x86)\IIS\Microsoft Web Deploy V3\msdeploy.exe
” -verb:sync -source:package="$package
"
Write-Host $cmd
cmd.exe /c $cmd
My problem is that variable is not replaced, when cmd.exe
is called. I get
cmd.exe /c "C:\Program Files (x86)\IIS\Microsoft Web Deploy V3\msdeploy.exe" -verb:sync -source:package="#{Path to package}"
However, #{Path to package}
is replaced, when Write-Host is called:
"C:\Program Files (x86)\IIS\Microsoft Web Deploy V3\msdeploy.exe" -verb:sync -source:package="c:\realPathToPackage\fromReleaseVariables"
How to force replacement before calling cmd.exe
?
Hi antontishchenko,
I’m sorry that you are running into this issue.
I tried running the PowerShell snippet you posted but ran into trouble with the nested quotes on $cmd. After a bit of testing, I was able to get it to work by adding an additional variable to account for the path to the .exe file.
When I adapt my test to your example, you get:
$package = $OctopusParameters["Test"]
$path = '"C:\Program Files (x86)\IIS\Microsoft Web Deploy V3\msdeploy.exe"'
$cmd = "$path -verb:sync -source:package=$package"
Write-Host $cmd
cmd.exe /c $cmd
Give this a try and let me know if you have any luck.
Regards,
Donny
My problem is that $package can contain spaces, that is why I need quotes.
About quotes: I just noticed that there are wrong quotes.
I need double quote then opening single quote(to escape) and then double quote again.
(Sorry, I don’t know how to type it in existing editor)
Hi antontishchenko,
I was able to re-work the script to account for the need for double quoting:
$package = $OctopusParameters["Test"]
$path = '"C:\Program Files (x86)\IIS\Microsoft Web Deploy V3\msdeploy.exe"'
$cmd = "$path -verb:sync -source:package=`"$($package)`""
Write-Host $cmd
cmd.exe /c $cmd
I was also able to find a great blog post that does a good job of explaining how to handle tricky quote situations in PowerShell: https://devblogs.microsoft.com/scripting/weekend-scripter-understanding-quotation-marks-in-powershell/
Let me know if the script works for you.
Regards,
Donny
system
(system)
Closed
2 July 2020 15:17
6
This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.