Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copying files after build with TeamCity

Tags:

teamcity

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?

like image 700
xam developer Avatar asked Jul 11 '15 13:07

xam developer


2 Answers

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.

like image 184
Lasse V. Karlsen Avatar answered Sep 25 '22 16:09

Lasse V. Karlsen


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

RoboCopy TeamCity

like image 35
Geovani Martinez Avatar answered Sep 23 '22 16:09

Geovani Martinez