7
votes

I have TeamCity setup on my server. I have it successfully downloading my source code, and building via Visual Studio. The logs say that the build is successful. However, at this time, the result of the build is in a directory like:

C:\TeamCity\buildAgent\work\688d47a33b8989b6\site

How do I take the contents of the url above and cop them to a directory on the same machine? For instance, I would like to take the contents of the directory listed above and put them in:

C:\WebSites\MySite

How can I do this copy-and-paste within TeamCity so that I have a true continuous integration cycle?

3

3 Answers

13
votes

Just create a step that uses ROBOCOPY or similar, use the command line step type and just do something like this:

ROBOCOPY . C:\WebSites\MySite *.* /E /MIR /NP
IF %%ERRORLEVEL%% LEQ 3 set errorlevel=0
IF %%ERRORLEVEL%% NEQ 0 EXIT /b %%ERRORLEVEL%%
EXIT 0

The 3 last lines there are because ROBOCOPY returns non-zero "ERRORLEVEL" values even for a successful copy. You want TeamCity to report the build as broken if ROBOCOPY indeed reports failure, but you want to ignore errorlevel values that indicate success, hence those 3 extra lines.

Also note the "." as the first parameter, the steps in TeamCity start with the working directory set to the working directory of the build, so it should match your build directory.

If you want to avoid overwriting production/testing web.config files with development web.config files, add this to the ROBOCOPY line:

/XF web.config

This will ignore web.config when copying.

9
votes

Here is a visual of the accepted answer, using TeamCity 9.1.1.

RoboCopy TeamCity

3
votes

Why do you want to do that. What happens to the existing contents, when next build happens? If you are looking for a way to keep the files produced from a build, you should be using Teamcity Build Artifacts. This way you can keep what was produced as in a specific build. All you need to do to get this done is update the Artefacts path under general settings like below: enter image description here