For example if I need replace some string to
%teamcity.agent.work.dir%\\nd_r\\bin\\isf
. But if variable teamcity.agent.work.dir
is C:\BuildAgent\work\
, it removes all backslashes and replace text to C:BuildAgentwork\nd_r\bin\isf
.
How I can escape all backslashes in variable, if I initially don't know about it's value?
\Q%env.NDRIVE%\E\nd_r\bin\isf - it doesn't work.
TeamCity does not support additional processing of values in %-references, it can only be used "as is".
In your case, possible workarounds are:
Since TeamCity 2017.1, File Content Replacer can run in the fixed strings mode (similar to that of grep -F
), as opposed to the original regex mode:
If you use versioned settings (either XML or Kotlin DSL variant), there's yet another mode available to you (in addition to REGEX
and FIXED_STRINGS
): REGEX_MIXED
. In this mode, the search pattern will still be interpreted as a regular expression, but the replacement text will be quoted so that \
and $
characters will no longer have any special meaning.
If you export your settings to Kotlin, sample File Content Replacer configuration might look like:
features {
replaceContent {
fileRules = "**/*"
pattern = "(?iu)the\h+pattern\h+to\h+search\h+for"
regexMode = FileContentReplacer.RegexMode.REGEX_MIXED
replacement = """%teamcity.agent.work.dir%\nd_r\bin\isf"""
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With