Using the percent sign in TeamCity build scripts

前端 未结 3 2423
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-03 09:33

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 Te

相关标签:
3条回答
  • 2020-12-03 10:14

    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?

    0 讨论(0)
  • 2020-12-03 10:17

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

    But 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: answer to your question will be:

    for /d %%%%x in ("c:\*") do @echo "%%%%x"
    
    0 讨论(0)
  • 2020-12-03 10:24

    It seems that TeamCity simply sticks what you enter into a .cmd file The for statement requires double percents in these cases. It then seems that TeamCity removes one of these % signs, hence why tspauld got it to work (this is also how i got it to run).

    In the logs it seems that TeamCity creates a file here Program Files\TeamCity\buildAgent\temp\agentTmp but the for cmd executes and dies too soon to see what it has written, presumably if the first line was a long executing task you would be able to check this (annoyingly 'pause' didn't work).

    0 讨论(0)
提交回复
热议问题