Wednesday, 8 May 2019

Why is my TeamCity build not being cleaned up?

We recently had an issue that was causing our builds to seemingly never be cleaned up. After a bit of digging this is how we discovered the issue:

  • In the build history there is an icon that shows you if TeamCity thinks there is a build dependency:
  • If you click on this you will see the build chain for the build and on that you can see what builds depend on this build in the chain.
For us however there were no dependent builds further down the chain so why was the build showing as being a dependency?

There is another tab of dependencies here. The delivered artifacts page. When we looked at this we saw that there was another build from the same build definition using this build as a dependency!

Why was this happening? In our build we were using the build definition credentials (%system.teamcity.auth.userId%, %system.teamcity.auth.password%) to download the artifacts of the last successful build for comparison. TeamCity seems to have seen this happening and marked the previous build as a dependency. Over time this means that every successful build has been a dependency of the next successful build and nothing could be deleted!

For us we were able to remove the artifact download from the script and after a few days the clean kicked in as expected and saved us a lot of disk space!

The other option is to ensure the Do not prevent clean-up option is set in the cleanup policy. Note that this does not affect builds that are snapshot dependencies: https://youtrack.jetbrains.com/issue/TW-59344