Automatically tag the build currently in progress
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:
<Target Name="TeamCityTag"
Condition="$(TEAMCITY_VERSION) != ''">
<HttpWebRequest TaskAction="Post"
Url="https://teamcity.domain.local/httpAuth/app/rest/builds/id:$(BUILD_NUMBER)/tags/"
ContentType="application/xml"
RequestContent="<tags><tag>completed</tag></tags>"
UserName="user"
UserPassword="password">
<Output TaskParameter="Status"
PropertyName="PostStatus" />
<Output TaskParameter="Response"
PropertyName="PostResponse" />
</HttpWebRequest>
<Message Text="Tagged: $(PostStatus) $(PostResponse)" />
</Target>
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:
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?
Please sign in to leave a comment.
Never mind - I realized I need to pass down %teamcity.buildid% instead of using BUILD_NUMBER