File Content Replacer having no effect on artifacts - teamcity

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:
Moves all js files to an "output" folder;
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.

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.

Related

Config file sharing in mercurial and VS

Our project uses custom xml config file, that is currently located under the project as .xml file, with Copy to output: always. Currently, it is present in the repository.
The problem is that every developer uses each own database (and each own configuration file), so ideally we need to have different configuration files, and we do not want to commit them to the external repository.
Sometimes the format of the configuration file is changed, and all of us need to update it. Also we have a build server that is configured to clean the folder before updating source from the repository and building it, so the default file (configured for build server) should be contained in the repository.
The problems is that sometimes a dev forget to check out it's local copy of the configuration xml when building, and his own config file goes to repository and brake many things. Is there any way to improve this schema so we don't need to remove config file from commit files every time we commit?
My solution is to exclude the app.config from VCS to prevent accidental commits to it. We have created an app.example.config which is checked in. A pre-build event validates if the app.config file exists and if it does not copies the .template to the .config file before compile of the codebase. This ensures the build server has a working config file which contains basic settings for all environments.
Example for PRe-build event in your project configuration:
REM copy .example files to .config files if needed
IF NOT EXIST "$(projectDir)\App.Config" IF EXIST "$(projectDir)\app.example.config" COPY "$(projectDir)\app.example.config" "$(projectDir)\App.Config"
IF NOT EXIST "$(projectDir)\Web.Config" IF EXIST "$(projectDir)\Web.example.config" COPY "$(projectDir)\Web.example.config" "$(projectDir)\Web.Config"
IF NOT EXIST "$(projectDir)\ConnectionStrings.Config" IF EXIST "$(projectDir)\ConnectionStrings.example.config" COPY "$(projectDir)\ConnectionStrings.example.config" "$(projectDir)\ConnectionStrings.Config"
IF NOT EXIST "$(projectDir)\Local.Config" IF EXIST "$(projectDir)\Local.example.config" COPY "$(projectDir)\Local.example.config" "$(projectDir)\Local.Config"
Config in repo contain data for TeamCity
Developers have MQ and patch in MQ-stack for converting default xml to local
Changed base xml require to edit (rebase) patch and remove conflicts
Here's another answer similar to the accepted one by Mark, but using the <Copy> task in the .csproj file, which you were apparently looking for:
how to ignore files in kiln/mercurial using tortoise hg "that are part of the repository"

Advice needed with Teamcity artifact paths

For a .NET Developer, the Teamcity artifact paths are not very straightforward.
Per project I do, I have a folder called BuildTools and, within it, folders called Drops and Inputs (drops being the reports and outputs inputs being the config files for various command line apps).
BuildTools/Drops/NDependOut => GenericSolution/Drops/NDepend
Is this correct? BuildTools is from the root of the (custom) checkout dir, and then GenericSolution is from the root of the artifacts path (Called "Artifacts" folder).
The other problem I have is that the NDepend report has a lot of images etc in the same folder as the .html file. How would I upload this? Do I upload the entire folder (in which case, is the syntax above correct?)
In general this is right. TeamCity has an option to zip artifacts before publish. For that use the following syntax
Folder/folder/*/ => destfolder/archive.zip
Another trick is to use TeamCity service message to publish artifacts dynamically from build script.

Change build label for Project Cruisecontrol.net

After some unexpected changes on the Cruisecontrol.net buildserver the artifacts directories were gone, and the build labels were reset on all projects. How can I change the build label value on the projects? We are using CCNetLabel variable in our scripts.
I tried updating the .state file with no success. it just overwrites the values on the next build. Also tried manipulating the latest log file in the artifact directory
You can use the <initialBuildLabel> value to set it in your .config file. This documentation for the Default Labeler gives more detail, but here is their example:
<labeller type="defaultlabeller">
<initialBuildLabel>1</initialBuildLabel>
<prefix>Foo-1-</prefix>
<incrementOnFailure>true</incrementOnFailure>
<labelFormat>00000</labelFormat>
</labeller>
I think this is what I did in my build config when I needed to do this, but have since removed it once it got going at the number I wanted.

How do I specifiy or override the file and path name for ftp publish location after a hudson build?

I am using hudson and the "Publish artifacts to FTP" option. It makes up its own directory based on the date and time of the build. I would like to override that with a fixed name/location. How can I do that? Is it possible?
What version of the FTP Publisher plugin are you using? I just installed the 1.0 version on Hudson 1.361, and in that version I can control the path by selecting the Flatten files option in the job configuration. Timestamp directories can also be disabled (that was the default).
That would solve path control. For the filename control, there doesn't seem to be a way to rename the file. You will either have to create an artifact with the right name during the build, or use some other tool for the ftp upload.
Edit: For example, the Post Build task, that can run arbitrary shell commands based on the result of the build.

How to configure Hudson to archive empty folders

I have the following sample / test configuration that has Hudson create a directory of empty folders. Its then instructed to archive everything within that folder, except it will not match empty folders and ends up archiving nothing. Whats more annoying is that Hudson does not alert you that nothing matches the search string "root**", but when it builds, it says nothing matches the search string.
(source: 86th.org)
We need Hudson to archive these empty folders for our installer since its expecting them. I fear this may not be possible because of the text "Files to archive".
At any rate, How can I configure Hudson to archive empty folders as an artifact.
You should create the artifact that you want in your build scripts, and then have hudson archive that file. So if you want a zip file that contains empty folders, do the appripriate zip command in your batch file or ant script. Then archive the output file.
Looking at the Hudson source code, it seems as if artifact archiving is meant to only match against files.
You might want to file a feature request or send an email to the USERS list, the Hudson team is pretty good about replying to requests and/or adding features in new releases.
I see three ways:
have your application NOT expect the folders but create them on demand.
or have the application create the folders at startup.
or you could just add dummy files in the folders :) just thinking out of the box.

Resources