Problem with File content replacer and properties
Im am trying to use the file content replace build feature to insert a path with an property into an c# file
The path is the following: %teamcity.build.workingDir%\Source (D:\teamcity\BuildAgent\work\67ae79e8354d77c6\Source)
The problem is that the backslashes is removed and I cannot escape them with \\
How can I solve this?
regards
Anders
Please sign in to leave a comment.
Hi Anders,
What version of TeamCity are you running? As you can see here: https://confluence.jetbrains.com/display/TCD10/File+Content+Replacer backslashes should be escaped (So writing "%teamcity.build.workingDir%\\Source" should work)
I have upgraded to 2017.1.1 to see if that solved the problem. It did not.
Well then the problem is that the backslashes "inside" the property %teamcity.build.workingDir% is not escaped. Is there a workaround that?
Another solution could be to use a property for the project hash code (67ae79e8354d77c6) and escape the rest of the path. Is there a property for the project hash code?
regards
Anders
Hi Aha,
Sorry for the delay in the answer. Version 2017.1 introduced the checkbox "Regex", that precisely will stop it from being treated like a regex, and it will start being treated as a literal string, which is what you seem to be wanting. If you are using versioned settings, you can go further and use the "REGEX_MIXED" mode, which will allow you to mix it up a bit.
More information here: https://confluence.jetbrains.com/display/TCD10/File+Content+Replacer#FileContentReplacer-FileContentReplacerSettings
and also this answer: http://stackoverflow.com/a/43373765/1343979).
Hi Denis,
It seems to me that the question was pointing to a fixed string replace, rather than a fixed string search. Am I correct in my understanding of the Regex checkbox which will perform a non-regex search which is not what is desired.
Regards,
Richard
Is this still an issue with TeamCity Enterprise 2017.2.2 (build 50909)? I am currently running into the same issue using the File Content Replacer trying to replace my Find What value with "%teamcity.build.checkoutDir%.
If it is not fixed are there any recommended workarounds to keep me moving forward using this Build Feature short of upgrading or using the "REGEX_MIXED" mode?
TeamCity Professional 2019.2.2 (build 71923) - I'm still having this issue, %-reference parameters are not escaped, so I get variables replaced as C:TeamCitybuildAgentworkproduct/source
I tried with both fixed and mixed modes
Hi all,
In our testing this still works as expected. Regex mode applies the replacement as a regex, without escaping anything. Mixed mode applies the replacement quoted, so it does pass the variables "as is". We have just double checked to make sure, and %teamcity.build.checkoutDir% for example results in "C:\BuildAgent\work\...." as expected.
If it still doesn't work, please share with us the lines from the build log related to the file content replacer, and for that same build, access the Artifacts tab -> Show hidden artifacts -> .teamcity\settings\buildSettings.xml and share with us the snippet of the extension with type JetBrains.FileContentReplacer
" %teamcity.build.checkoutDir% for example results in "C:\BuildAgent\work\...." as expected." : This is the problem, when the property is retrieved in my java code, the slashes are escaped, so the resulting string is "C:BuildAgentwork..." .
I resolved just creating a final Build Feature that replaces the "\" with "/"