Your browser was unable to load all of the resources. They may have been blocked by your firewall, proxy or browser configuration.
Press Ctrl+F5 or Ctrl+Shift+R to have your browser try again.

Passing commas as parameters #2695

bakerb ·
We use variables to hold command-line parameter strings. Some of our scripts accept comma-delimited command-line parameters.

I've been unable to find a way to have QuickBuild pass a command-line parameter that includes a comma:

Computer1,Computer2 - Parameter is passed as Computer1\
""Computer1"\,"Computer2"" - Parameter is passed as Computer1\
"Computer1"\,"Computer2" - Parameter is passed as Computer1\
\"Computer1\"\,\"Computer2\" - Parameter is passed as "Computer1"\
\"Computer1\"\,\"Computer2\" - Parameter is passed as "Computer1"\

Quotes can be escaped but not commas?
  • replies 5
  • views 5262
  • stars 0
robinshen ADMIN ·
I created a variable "params" with value "param1,param2" and then create a command build step to run below command
cmd /c echo ${vars.getValue("params")}
Run the configuration and the step outputs "param1,param2" as expected.

Or are you mentioning something else?
bakerb ·
If you try passing the string to a batch file, it will only pass the first value:

Shell/Batch Command: TestParametersWithCommas.bat ${vars.getValue("params")}

params variable prompts for input: SERVER1,SERVER2

Log results:
10:20:29,603 INFO - D:\qb_sfa\workspace\ubit\SFA\Testing\SFA\Automation\Deployment>echo SERVER1
10:20:29,603 INFO - SERVER1
robinshen ADMIN ·
Please make sure you are running QB 5.1, it has the enhancements of wrapping command execution inside a batch file to make it behaving the same as if you executing from command prompt. For instance, if content of the batch file to be executed is:
echo off
echo param1: %1
echo param2: %2


If value of params variable is value1,value2, the log will output:
param1:value1
param2:value2
If value of params variable is "value1,value2" however, the log will output:
param1:"value1,value2"
param2:

And this behaves the same as if you are running the batch command from command line.
bakerb ·
Sorry for not mentioning this sooner but we're actually seeing this behavior when running Powershell commands. However that should not make a difference to the output of QuickBuild. Since you started with a batch file example I kept going with it:

Our requirements for Powershell are a bit different than with the batch example I gave earlier. We actually need quotes around each parameter as well.

Here are results from my testing with various formats and escape characters for our Powershell command. Note that none of them ever return "Server2" unless there are no commas in the parameter/variable. What we really need to see is "Server1","Server2":

params input: ""Server1","Server2""
Log output: params=\"powershell.exe -file .\Deploy.ps1 /SERVICES INT MAIN_DEV_1.0.1135 TestService Server1\",

params input: "Server1","Server2"
Log output: params=\"powershell.exe -file .\Deploy.ps1 /SERVICES INT MAIN_DEV_1.0.1135 TestService Server1\",

params input: \"Server1 Server2\"
Log output: params=\"powershell.exe -file .\Deploy.ps1 /SERVICES INT MAIN_DEV_1.0.1135 TestService "Server1 Server2""\",

params input: \"Server1\"\,\"Server2\"
Log output: params=\"powershell.exe -file .\Deploy.ps1 /SERVICES INT MAIN_DEV_1.0.1135 TestService "Server1"\",

params input: \"Server1\"\,\"Server2\"
Log output: params=\"powershell.exe -file .\Deploy.ps1 /SERVICES INT MAIN_DEV_1.0.1135 TestService "Server1"\",

params input: "Server1"\,"Server2"
Log output: params=\"powershell.exe -file .\Deploy.ps1 /SERVICES INT MAIN_DEV_1.0.1135 TestService Server1\",

params input: ""Server1"\,"Server2""
Log output: params=\"powershell.exe -file .\Deploy.ps1 /SERVICES INT MAIN_DEV_1.0.1135 TestService Server1\",

params input: Server1,Server2
Log output: params=\"powershell.exe -file .\Deploy.ps1 /SERVICES INT MAIN_DEV_1.0.1135 TestService Server1\",

params input: "'Server1','Server2'"
Log output: params=\"powershell.exe -file .\Deploy.ps1 /SERVICES INT MAIN_DEV_1.0.1135 TestService 'Server1'\",
bakerb ·
Another combination ended up working for us: \"server1,server2\"
We'll have to revise our Powershell script a bit, but this will work.