TeamCity 批处理脚本文件大小 % 冲突

TeamCity Batch Script File Size % Conflict

我在 TeamCity 构建步骤中将以下内容作为自定义脚本:

for %%A in (*.err) do (
  if not %~zA==0 (
    echo."%%A" contains errors.
    set "retval=1"
  )
)

TeamCity 日志抱怨 "A was unexpected at this time."。有谁知道解决方法是什么?


最终解决方案是:

for %%%%A in (*.err) do (
      if not %%%%~zA==0 (
        echo."%%%%A" contains errors.
        set "retval=1"
      )
    )

谢谢。

来自official documentation

If you want to prevent TeamCity from treating text in the percentage signs as reference to a property you can escape them by using two percentage signs. Every occurrence of "%%" in the values where property references are supported will be replaced to "%" before passing the value to the build. e.g. if you want to pass "%Y%m%d%H%M%S" into the build, change it to "%%Y%%m%%d%%H%%M%%S"

因此您的代码如下所示:

for %%%%A in (*.err) do (
  if not %%%%~zA==0 (
    echo."%%%%A" contains errors.
    set "retval=1"
  )
)