So, I want to tag a build if it gets to a certain point in the msbuild file. The tag is important for other build configurations to find certain artifacts of those builds so tagged.
I thought that this would be easy via the rest API, so I added a target to my build file to invoke it, eg:
Condition="$(TEAMCITY_VERSION) != ''">
<Message Text="Tagged: $(PostStatus) $(PostResponse)" />
Sure enough, when I test this target to tag build numbers of builds that have already finished, it works perfectly. However, when I invoke this target as the last target in an actual build run by TeamCity (in order to effectively have the build "tag itself"), I get eg:
[22:20:00][HttpWebRequest] C:\BuildAgent\work\dc752afaa7933393\TC.targets(548, 5): The remote server returned an error: (404) Not Found.. Status: ProtocolError
[22:20:00][HttpWebRequest] C:\BuildAgent\work\dc752afaa7933393\TC.targets(548, 5): Error has occurred during request processing (Not Found). Error: jetbrains.buildServer.server.rest.errors.NotFoundException: No build can be found by id '943'. Could not find the entity requested. Check the reference is correct and the user has permissions to access the entity.
I can only assume that since the build with the id $(BUILD_NUMBER) doesn't actually exist (in a finished state) yet, the rest API can't see it yet. I guess I could add another configuration that's triggered on completion of the first, that just runs the new target by itself, but I don't necessarily want to always create the tag - only when the build completes (successfully or unsuccessfully) under certain conditions tracked in the original build targets, and that information would be hard to determine from a completely separate build configuration.
Does this make sense? Is there a simple way to achieve the effect of having a build tag itself when certain conditions are met?