TeamCity Command Line Runner: Setting and using variables

16,671

You need to escape the variable with %% so it isn't treated as a TeamCity variable.

echo "Distributing"
set VERSION=< component_version.txt
echo %%VERSION%%
echo "Copying files to dir \path\to\dir\%%VERSION%%\"
mkdir \path\to\dir\%%VERSION%%\
Share:
16,671
bwallace
Author by

bwallace

Updated on July 28, 2022

Comments

  • bwallace
    bwallace over 1 year

    Within a TeamCity project running on a windows agent, I would like to read the contents of a file and then create a directory based on the file contents.

    Performing this operation as a command line build step seems logical. I have tried creating a local variable "VERSION" as well as a custom teamcity parameter, but I can't get either to work. It does not seem that windows cmd variables are playing nicely with the TeamCity defined env and system variables. I am using the following custom script:

    echo "Distributing"
    set VERSION=< component_version.txt
    echo %VERSION%
    echo "Copying files to dir \path\to\dir\%VERSION%\"
    mkdir \path\to\dir\%VERSION%\
    

    Any suggestions on how I can achieve this?

  • Mario Tacke
    Mario Tacke over 7 years
    The double %% is what I missed. Thanks!