Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TeamCity - passing parameter values with whitespace to command line

Tags:

teamcity

I'm passing some TeamCity parameters to the command line build step. The problem comes when the parameter value contains spaces, e.g.:

%env.TEAMCITY_BUILDCONF_NAME%  ---> My TC Project

Is there a way to replace white spaces with some other character, for example underscore?

%env.TEAMCITY_BUILDCONF_NAME%  ---> My_TC_Project
like image 274
finspin Avatar asked Feb 05 '13 20:02

finspin


2 Answers

You can typically keep using the white spaces if you wrap the parameter in double quotes:

%program.files.dir% => C:\Program Files (x86)

Executable: dir

Parameters: "%program.files.dir%"

like image 110
John Hoerr Avatar answered Nov 07 '22 14:11

John Hoerr


I don't know how to replace spaces with underscore, but I had an issue with whitespaces. In a TeamCity build step, I was trying to run an sqlcmd as Executable with Parameters

-S %sql_server% -U %sql_username% -P %sql_password% 
-i "custom_script.sql" -d "%custom_db%"
-v DealerName="%DealerName%"

where DealerName was "Great Dealer Ltd" but it didn't work with white spaces, even with double quotes.

It fixed the issue by setting it as a Custom Script like

sqlcmd -S %sql_server% -U %sql_username% -P %sql_password% 
-i "custom_script.sql"  -d "%custom_db%"
-v DealerName="%DealerName%"

and (thanks to my boss suggestion) it worked like charm.

Even if is not the precise answer to your question, it could be useful for similar issues.

like image 21
znn Avatar answered Nov 07 '22 13:11

znn