Update blocked binaries after build - teamcity

I want to copy binaries to stage server as the last step of build. Previously I was doing it for asp.net web sites powered by IIS. There were no problems as IIS doesn't block any boundaries. Now I need to do the same for executable server application (it executes some background tasks) which blocks at least its exe file. So I need somehow to close application, update binaries and then run application again.
What is the best way to achieve it using TeamCity?

I'm seems like your staging server is a windows machine. If that's the case, I'd recommend using two executables from the PsTools Suite (PsKill and PsExec) to kill/start your process. Here's how I would set everything up in TeamCity:
Download the PsTools Suite, and copy the contents of the zip file to a folder on the build server. I'll be using C:\Program Files\PsTools in my example.
Create a batch file that kills the executable server application, copies the appropriate binaries, and starts the application again. The batch file would look something like this:
"C:\Program Files\PsTools\PsKill" -accepteula \computername -u username -p password name_of_process_to_kill.exe
copy files - I'm assuming you copied binaries to your ASP.Net staging site using the command line. If not, I can provide more details later.
"C:\Program Files\PsTools\PsExec" -accepteula \computername -u username -p password -d "path_and_name_of_executable_on_remote_server" optional_commandline_args_here
Add a new command line build step to your TeamCity build configuration that executes the batch file created in step #2.
I hope this helps!

Here is how I solved it. I added Command Line step with following Custom Script:
taskkill /IM MyApplicationProcessName /F
xcopy RelativePathToBuildBinaires PathWhereToDeployBinaries /s /e /y
start PathToMyApplicationExeInDeployFolder
Initially it didn't work as TeamCity build agent worked as service (which do not have UI). Then I disabled service and started build agent as console (by TeamCityFolder/builagent/bin/agent.bat). And it worked.

Related

bat file can not be executed in TeamCity

I have a bat file in which I perform the copying folder from my computer to a remote computer in a shared folder. If I run it on your computer from the command line, everything works. If I add this bat file TeamCity it gives an error "error in Access." If I instead of the path to the shared folder write path to a folder on my computer, it is normally all copies TeamCity.
so looks bat file when copying to the local computer
cls
SET ARTPATH="C:\myfolder\"
cd %ARTPATH%
xcopy DatabaseUpgrader /e /Y C:\example\
cd c:\
so looks bat file when copying to a remote computer in a shared folder
cls
SET ARTPATH="C:\myfolder\"
SET DBPATH=\\10.73.0.3\DBUpdater\DatabaseUpgrader\
cd %ARTPATH%
xcopy DatabaseUpgrader /e /Y %DBPATH%
folder DBUpdater now shared all network users. I think that launches White TeamCity file under the user has no rights. how to fix it but do not know
If your build agent is installed as a service, try the following:
Run the service under account that has enough rights for the share, by default it is installed under SYSTEM account that can't go outside of the box.
Change agent installation from service to console app, here's a TeamCity doc saying that you need to do it to access network shares: http://confluence.jetbrains.com/display/TCD8/Known+Issues#KnownIssues-Windowsservicelimitations
My knowledge of Windows is very poor, but try to compare the permissions of these two users (the one that you are logged in as, and the second that TC agent is run by).

Invoke batch file in .msi or .exe

I have a requirement which needs a batch script to be invoked before the .msi or .exe package can deploy files to the desired location. I created a setup project and I am ablr to get a .msi and .exe when I build it. My main concern here is that, when I run the exe or msi, the installer deploys the code to the desired location but I have to stop the service brfore copying and start it back after the files are copied. Is there anyway that I can invoke a batch scrip to stop the service before the files are deployed and then invoke another batch script after the files are deployed. I tried using custom action but didnt work, any suggestions are highly appreciated. Thank you.
#ECHO OFF & ECHO This is an Install.bat
NET STOP "the service"
START /WAIT "Installation in progress..." "The installer.msi"
NET START "the service"

Jekyll private deployment?

I have created jekyll site. Regarding the deployment I don't want to host on github pages. To host private domain I came know from documentation to copy the all files from _site folder. That's all wicked.
Question:
Each time I add new blog post, I am running cmd>jekyll build then I am copying newly created html to hosted domain. Is there any easy way to update without compiling each time ?
The reason, Why I am asking is because it will updated by non technical person
Thanks for the help!!
If you don't want to use GitHub Pages, AFAIK there's no other way than to compile your site each time you make a change.
But of course you can script/automate as much as possible.
That's what I do with my own blog as well. I'm hosting it on my own webspace instead of GitHub Pages, so I need to do these steps for each update:
Compile on local machine
Upload via FTP
I can do this with a single click (okay, a single double-click).
Note: I'm on Windows, so the following solution is for Windows.
But if you're using Linux/MacOS/whatever, of course you can use the tools given there to build something similar.
I'm using a batch file (the Windows equivalent to a shell script) to compile my site and then call WinSCP, a free command-line FTP client.
WinSCP allows me to store session configurations, so I saved the connection to my server there once.
Because of this, I didn't want to commit WinSCP to my (public) repository, so my script expects WinSCP in the parent folder.
The batch file looks like this:
call jekyll build
echo If the build succeeded, press RETURN to upload!
pause
set uploadpath=%~dp0\_site
%~dp0\..\winscp.com /script=build-upload.txt /xmllog=build-upload.log
pause
The first parameter in the WinSCP call (/script=build-upload.txt) specifies the script file which contains the actual WinSCP commands
This is in the script file:
option batch abort
option confirm off
open blog
synchronize remote -delete "%uploadpath%"
close
exit
Some explanations:
%~dp0 (in the batch file) is the folder where the current batch file is
The set uploadpath=... line (in the batch file) saves the complete path to the generated site into an environment variable
The open blog line (in the script file) opens a connection to the pre-saved session configuration (which I named blog)
The synchronize remote ... line (in the script file) uses the synchronize command to sync from the local folder (saved in %uploadpath%, the environment variable from step 2) to the server.
IMO this solution is suitable for non-technical persons as well.
If the technical person in your case doesn't know how to use source control, you could even script committing & pushing, too.
There are a number of options available which are mentioned in the documentation: http://jekyllrb.com/docs/deployment-methods/
If you are using Git, I would recommend the Git Post-Receive Hook approach. It simply builds the site after the new code is received:
GIT_REPO=$HOME/myrepo.git
TMP_GIT_CLONE=$HOME/tmp/myrepo
PUBLIC_WWW=/var/www/myrepo
git clone $GIT_REPO $TMP_GIT_CLONE
jekyll build -s $TMP_GIT_CLONE -d $PUBLIC_WWW
rm -Rf $TMP_GIT_CLONE
exit
Since you mentioned that it will be updated by a non-technical person, you might try something like rack-jekyll to automatically rebuild when new files are FTP'd.

Jenkins Windows slave failing the Play! framework build

We are using the Play! framework and I've setup our Jenkins CI to run auto-test and other things on a master Unix machine. As a second step I want to setup a windows slave to run some in browser webdriver tests. Unfortunately my build doesn't get to that point. The source checks out fine in the workspace directory. As a first build step I run
play clean
Which seems to fail everytime. I've given full permissions to admin for that directory and I'm running the jenkins slave under that administrator like so
runas /noprofile /user:DOMAIN\Administrator "javaws http://jenkins:8080/computer/Keith/slave-agent.jnlp"
The console output I see from jenkins is:
Building remotely on Keith in workspace C:\Documents and Settings\administrator\My Documents\Jenkins\workspace\windows
Updating http://svnrepo..
At revision 448
no change for http://svnrepo.. since the previous build
play path is C:\Software\Play\play
Executing C:\Software\Play\play clean "C:\Documents and Settings\administrator\My Documents\Jenkins\workspace\windows"
[windows] $ C:\Software\Play\play clean "C:\Documents and Settings\administrator\My Documents\Jenkins\workspace\windows"
Build step 'Play!' marked build as failure
Finished: FAILURE
Note that when I run the command below manually on the windows box it works fine:
C:\Software\Play\play clean "C:\Documents and Settings\administrator\My Documents\Jenkins\workspace\windows"
Anyone got any ideas what I'm doing wrong?
Thanks!
I had the same problem and I solved it by adding .bat at the end of play path. In your case, you should configure play path in jenkins as C:\Software\Play\play.bat (not just C:\Software\Play\play).

Move files to remote file share after build

I want to create a post build script that moves files from the build directory to a remote (UNC) file share.
This line:
xcopy "C:\TeamCityBuild\project\WebSite\*" "\\192.168.1.1\WebSite\" /C /R /Y /E
Works fine when it is ran in a DOS-window but when TeamCitys buildrunner sln2008 tries to run it it fails with the message "Invalid drive specification"
I have shared the folder with full rights for 'Everyone' on the remote server.
Any ideas?
Just a guess. Not quite sure if it solves your problem. We had a similar problem using CruiseControl and deploying our application to remote JBoss server.
We've added
net use \\192.168.1.1\Website ...
before each copy. So that it 'mounts' the remote share before trying to access it. Note: you probably need to specify the username and password for the command (consult the command line for details).
The 'net use' seems needed even if you run the automated job as the same user you log on manually. These two kinds of sessions seem not to share remote shares information.
I've never used TeamCity Buildrunner sln2008, but if it runs as a service, then it is probably running under the "Local System" account, which doesn't have network access. Change the service properties (under the "Log On" tab) so that the service logs on as a user with permissions to that network share.
I don't beleave it works because the agent is running as a system service so it has limited network access (I beleave).
Instead of trying to use a post build step to copy the output, I think you should look into using TeamCity's Build Artifact's. That's what we use at my work altho we are new to TeamCity as well. What I don't know is if Build Artifact system will do extactly what you want.
You could try nANT
http://nant.sourceforge.net/release/latest/help/tasks/copy.html

Resources