Buildrunner cleanup

I currently have a problem where my ANT runners cause my system to become unstable if I stop then via the web front end.

The ANT runners spawn various other tools that lock resources and keep DLLs and other handles open.

When they are killed these are in an unknown state and the next run then fails.

What would be the easiest to implement a listener or something that can shut down the child processes correctly ?

Is this something I can do with a ANT or do i need to write a custom teamcity build runner for this ?

I am not a web developer so am not keen to delve into a custom buildrunner if i don't have to

Comment actions Permalink

Hi Morne

This is probabluy the issue described in TW-11856. When you stop a build, agent tries to kill child processes, but cannot find orphaned processes.

You could use Swabra build feature. It allows to kill processes if they keep open file handles in the checkout directory.
In 6.5 version it also allows to monitor additional directories.


Comment actions Permalink

My problem is how the processes gets killed.

The correct list of processes and child processed are killed, not closed.

The clean way to shut down processes is shown in

Some of my processes are GUI based and needs the WM_CLOSE messages to currectly shut itself and down and its child processes.

All i need is the mechanism shown in the Microsft tech note.

Comment actions Permalink

Current implementation of build agent gives you no chance to confgirure processes termination. It is possible to write an agent-side plugins (this would no need to implement any web UI) and would stop all processes before agent kill them.

Please take a look at plugin development documentation at

You need to register a listener for AgentLifeCycleListener and provide an implementation for beforeBuildFinished or beforeBuildInterrupted methods. Implementation may work as much time as it needed to ensure all processes were shutdown in the right way.  

You may check for some specific system propertity before checking for processes. Use AgentRunningBuild interfact to get information from running build.

Please let me know if you need more details on how to write or pack plugins for TeamCity. Feel free to ask more questions!

Comment actions Permalink

Yes, some more documentation with a detailed walkthrough would be useful.

I had a look at the documentation and examples but there are parts where it is expected the reader knows about certain web technologies and other bits and pieces....

Comment actions Permalink

I've attached a link to plugins documentation we have now.
Another way to learn is to look thorough examples.
Please take a look to plugins list. Most of plugins are open-source and you may see how to do it.

For example, you may take a look to PowerShell runner:

Note, you do not need to write a plugins for server side. All you need is to write a
plugin for agent side. So in that sample check only powershell-agent module.


Please sign in to leave a comment.