As far as I can tell, TeamCity does not have a built-in option to disable publication of an artifact if the assembly fails.
However, in the build script called by TeamCity, you can try:
Removing artifact paths from the assembly configuration, and instead transferring the corresponding TeamCity service messages with your artifact paths only after the tests have been completed and successfully.
Only copying files in the path of artifacts configured in TeamCity after the tests are completed and successful.
Bilal source share