Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using the percent sign in TeamCity build scripts

Tags:

teamcity

I am trying to set up a TeamCity build process that runs a custom command line script. The script uses a variable so it needs a percent sign (e.g. %x). But TeamCity uses percent signs for its properties (e.g. %build.number%), so the percent sign in the script gets removed when it runs.

If the script contains this:

for /d %x in ("c:\*") do @echo "%x" 

This is what it actually runs:

for /d x in ("\*") do @echo "x" 

How can I write my script so it can include variables?

like image 868
tspauld Avatar asked Dec 08 '10 16:12

tspauld


People also ask

How do you run a command in Teamcity?

Specify the working directory where the command is to be run (if it differs from the build checkout directory). Specify the mode: run an executable with parameters or run custom shell/batch script (see below). The option is available if "Executable with parameters" is selected in the Run drop-down menu.


2 Answers

If you want to pass % to TeamCity, you should escape it with another %, i.e. for % it must be %%`.

But the Windows command line considers % as an escape character, so you should escape it again adding another % before each %, i.e. for %% you should pass %%%%

Flow is:

%%%% in cmd -> %% in TeamCity -> % actual sign. 

tl;dr: the answer to your question will be:

for /d %%%%x in ("c:\*") do @echo "%%%%x" 
like image 75
Marat Turaev Avatar answered Oct 08 '22 05:10

Marat Turaev


Try for /d %%x in ("c:\*") do @echo "%%x" (i.e. duplicate the % signs).

But there should be a way to tell TC to leave the file alone. It would be horrible if TC would remove the percent signs in the sources. Therefore, I'm pretty sure that you did something in the configuration to enable replacement of %.

On a similar note, is it really TC that messes with the script? Or are you using a build tool to generate the script or something like that?

like image 34
Aaron Digulla Avatar answered Oct 08 '22 06:10

Aaron Digulla