2

I'm using a relatively new feature of TeamCity: File Content Replacer. In my current setup I have a version.js file in my VCS:

window["MyPlugin"].version = "1.0.##VCS_REVISION##.##CI_BUILD_NUMBER##";

I use the File Content Replacer build feature to replace that last part with:

%build.vcs.number%.%system.build.number%

So far so good!

I have one relevant build step. It's an MSBuild step, but it does nothing except call a ps1, which does two relevant things:

  1. Moves all js files to an "output" folder;
  2. Zips all js files into a "zips" folder;

Those are also my two artifacts (an output folder, and a zip file).

However, the File Content Replacer reverts its changes, but this revert is also reflected in artifact nr 1, which are files that are not under version control (even though they are located as a subfolder of my project folder). The version.js file in the zip file is not reverted.

If I change artifact 1 to be my/output/folder => all.%build.vcs.number%.zip then the zip file will also contain a reverted state instead of the output I want.

How do I set TeamCity up so that the artifact files are not affected by this revert? Or do I need something other than this Build Feature?

I'm using TeamCity 9.1.3 build 37176 running on Windows 2012 Server (VM) and the default database for evaluation purposes. I'm using TFS 2013 as my VCS.

PS. I've also asked about this on the JetBrains forums.

Jeroen
  • 60,696
  • 40
  • 206
  • 339

1 Answers1

7

File content replace reverts changes before "Publishing artifacts" stage. This is "by design". You can check it in the build log. However you can find modified files in hidden artifacts .teamcity/JetBrains.FileContentReplacer/.
If you want to publish changed file as regular artifact you should create a copy of the file (or pack/archive it as as you've already done). Also instead of using File Content Replacer build feature you can create a script that would make needed changes which aren't reverted.

Alina Mishina
  • 3,320
  • 2
  • 22
  • 31
  • FWIW, I've placed a TeamCity feature request to improve this: https://youtrack.jetbrains.com/issue/TW-43173 – Jeroen Nov 13 '15 at 14:14
  • Yeah this is bizarre. These types of operations used to be "Build Steps" prior to V9, which is IMO where it belongs. I think the issue is how teamcity keeps the checkout directories around, instead of starting from scratch everytime. AppVeyor handles this aspect better, where you start from scratch but can specify certain directories, like (nuget)packages or node_modules etc to "preserve" between builds. This is a much better solution then the checkout folder sticking around and FileContentReplacer "restoring the file" after a build is complete. – enorl76 Nov 24 '16 at 08:50
  • This is exactly the time when JetBrains' motto comes up to my mind. Instead of just adding this build feature you need to fall back to bash and sed. Go [here](https://stackoverflow.com/a/1583282/1633984), my friend. – vehsakul Nov 16 '18 at 16:26