5
votes

I'm surprised I can't find any documentation about this, but anyway...

Sometimes my TeamCity build hangs, and I end up needing to stop it. The build process produces several log files on disk, which TeamCity then publishes as build artifacts. However, if I stop the build, then TeamCity refuses to publish the logs:

Build was interrupted. Artifacts will not be published for this build

The files still exist on disk, it's just that TeamCity doesn't publish them any more. This is particularly exasperating since I really, really need to see what's in those logs so I can work out why the build hung in the first place.

Is there some way I can force TeamCity to always publish the build artifacts, even if I have to abort the build?

(I've seen several questions asking how to stop TeamCity publishing artifacts if the build fails, so I'm a bit puzzled as to why my setup isn't doing this already, but anyway...)

PS. I realise I can just manually log into the build server to see the logs, but kind of the whole point of TeamCity is to automate stuff like that for me...

3

3 Answers

4
votes

I think enabling hanging build detection is a good idea in general (you can set a failure condition on a build taking longer than n minutes to finish), but if you are interested in the artifacts that have been created so far by a build that is eventually stopped/hanging, the following may be useful:

You can output TeamCity service messages to immediately publish artifacts. These artifacts will remain available also when a build is stopped. Example:

##teamcity[publishArtifacts '/tmp/logfile => logs']

This will make sure the file /tmp/logfile is published into artifacts directory logs.

An additional advantage is that you will have these artifacts available on the build's artifacts tab right away, which could help decide if a build should be cancelled or not.

2
votes

TeamCity has no way of Publishing on a stopped build, which is different than a failed build. Stopped builds are more like a killed process, whereas failed builds are a non-zero exit code.

Instead, I recommend configuring TeamCity so that you don't have to stop a build. There are two options to enable: hanging build detection and the "it runs longer than" build failure condition. Both should help TeamCity automatically terminate the build rather than you having to stop it.

This way, you will get a failed build rather than a stopped build, and your artifacts should publish.

0
votes

Could it be last 'Command Line' step of the build
with option 'Execute step: Always, even if build stop command was issued'
which will output publish artifacts directive?