Can this be done with Teamcity and if yes how?

Hi All

Still no luck getting my build to work Slowly TeamCity is getting on my nerves. Sigh

Anyway here's the situation:
- I have TeamCity 4.5.4 installed, with an MS SQL 2008 express database (which seems to work fine and is most likely not related to my issues)
- I've got a bzr repository which holds my source code. I have installed the bzr plugin for TeamCity and pointed it at my repository. TeamCity is detecting the changes in the repository so I'm assuming it works
- My build script is psake (powershell make) script which is stored in my repository.
- The bzr plug-in does not provide an ability to check the source out on the agent so I'm using a custom script (again a powershell script) for checking out the sources. Outside teamcity this script works, inside teamcity I just can't get it to work. The script looks like this:



$currentDir = pwd
$vcsRoot = $args[0]
$checkoutDir = $args[1]
$revno = $args[2]
$script = $args[3]
$command = $args[4]

& bzr checkout $vcsRoot $checkoutDir --revision=revno:$revno

$fullPath = Join-Path $checkoutDir $script
$fullPath

. $fullPath
& $command

sl $currentDir



 


- This script is called from the command line runner by setting the command executable to powershell.exe (which is in the path) and the command parameters to: -Command "d:\repository\TeamCityBootstrap.ps1'" (which is the path to the script). I've been trying to pass the VCS root dir, the checkout dir and the revision number of the powershell script but I simply can't convince TeamCity that it's not that hard (apparently it's very hard to pass any kind of useful argument over the command line).

So that's the story. Does anybody have any useful advice. I've read the powershell related posts in the tracker and on the forum but none are of help in my situation. I've also read this (http://www.jetbrains.net/devnet/thread/282651) but that didn't help either. I refuse to put Teamcity related values in my bootstrapper. That should really not be necessary.

Short of coding up my own runner / VCS plugin is there anything I should try or should I just give up and use another build system. I do really like TeamCity but if it can't checkout the source and invoke my build script then it's useless. Oh and I've tried MsBuild scripts which got really messy and still didn't work and I'm not intending to use Nant because I don't want to install yet another dependency on my system.

Thanks

Patrick

6 comments
Comment actions Permalink

So what is not working with your powershell script? What output do you get? Can you provide logs?

Also please check that your agent (if it is started as service) is not running under the SYSTEM account (run it under some existing user account), because it may cause problems for some command line tools. You can also try to start agent via agent.bat and see whether it helps.

0
Comment actions Permalink

Hi Pavel

I've attached the logs that had stuff in them. I think the most relevant parts are the sections from today (27th of August 2009).

The main problem is that either powershell simply hangs and doesn't produce output. I've managed to get it run my script a few times but then I hung on me trying to pass some values from teamcity.

So the problems so far:
- The script doesn't seem to get started. I've got some debug lines in the script right at the beginning but those aren't being placed in the teamcity log output. The build agent simply sits there at near 0 CPU so I'm guessing it's waiting for something (it shouldn't)
- The script runs but the variables passed to it are incorrect. I used to pass the TeamCity properties (teamcity.build.checkoutdir) until I read the post saying that you can't. Then I defined an environment variable with the same name but that didn't work either.
- I've tried giving the commandline to powershell as -command "<COMMAND_HERE>" but that didn't seem to work either.

Can you explain the agent.bat thing a bit more? Does that start the agent in case it's not running? I don't think that's the problem. I have teamcity installed on my own machine and the 'server' and the agent are both the same machine so there shouldn't be an issue for it to start.

In short I have no idea how to make this work. In theory it shouldn't be this hard I think.

Thanks for helping out!

Patrick



Attachment(s):
TeamcityBuildRunnerSettings.png
TeamcityEnvironmentVariable.png
wrapper.log
teamcity-agent.log
launcher.log
0
Comment actions Permalink

Ok, first of all try to wrap your powershell script in a bat file (see more on this here: http://jetbrains.net/tracker/issue/TW-6021). It is a workaround which helps to overcome powershell hanging issue (we beleive this is a problem in powershell itself).

As for the environment variable, you should use system. prefix, i.e. value of your environment variable should be: %system.teamcity.build.checkoutDir%

Now about agent.bat. Agent can be started as service and builds launched by agent running as service won't be able to do some things (like communicating with desktop or accessing mapped drives). Note that this is not TeamCity limitation, that's how windows services work. Also agent service can be installed to run under the Windows SYSTEM account which simply may not have enough privileges to run your builds.

So I would recommend to start agent via agent.bat, and make your build pass under such agent. If everything is ok, run agent as service and see how your build behaves.

0
Comment actions Permalink

Hi Pavel

I've been experimenting a bit more with the stuff in the links you gave me. I've written a bat file which calls the script. I've managed to pass the parameters too. So far so good. Now all I need to do is manage to exit powershell
I will have a further hunt but if you have any suggestions they would be welcome. Also a powershell build runner would be even more awesome. Hudson has one that works pretty well so I guess it must be possible

In any case thanks heaps

Patrick

0
Comment actions Permalink

Thank you for good suggestion about powershell runner, I filed feature request: http://www.jetbrains.net/tracker/issue/TW-9310
Feel free to watch/vote for it.

0
Comment actions Permalink

Hi All

For the information of anybody finding this thread while looking for a way to use powershell with TeamCity. It turns out that the guesses were correct. When running a powershell script a hang occurs because powershell is waiting for something. From http://www.vistax64.com/powershell/156786-powershell-starts-but-never-exits-when-invoked-wscript-shell.html it appears that powershell is waiting for the input stream to be closed. I'm pretty sure it wasn't fixed in powershell V2 given that I'm currently running the Win7 RC which should have (the near final version of) powershell V2.

The solution I've used is to write a small C# console app which gets the command line arguments for the script (e.g. from TeamCity) and then calls into the powershell DLL to execute scripts etc. If anybody is interested I can post the script here (free for all to use).

Of course it would still be cool if we could get a powershell runner in TeamCity 5

Thanks

Patrick

0

Please sign in to leave a comment.