Finding Build Configuration Last Built Date
Hi there,
I am trying to figure out a way of retrieving the date that a build configuration was last built via the TeamCity API.
I am able to retrieve the statistics for a build by running the following query:
http://teamcity.com/app/rest/builds/id:523139
This will return (among other statistics) the triggered date for the build - would this be the correct value to use in this instance?
Thanks,
Sean
Please sign in to leave a comment.
Hi,
Your statement would be correct but that would require knowing the ID of the last build of the build configuration. You can use the locator parameter to, instead of just passing an arbitrary ID, find the builds from the build configuration. For example:
<url>/app/rest/builds/?locator=buildType:<build_config_id>,count:1&fields=build(queuedDate)
will return only 1 build, from the build config with the ID you pass and will only give you the queued date for it. You can alter the "fields" parameter to give you any information you would like.
Whether it's the correct value or not would depend on your needs, and "last built" is a very broad term. queued date will return when it was added to the queue (which is roughly equivalent to when it was triggered), startdate when it was removed from the queue to start processing, and enddate when it ended. Which of this values would be right for you is something we cannot determine for you. In some cases this values might be just a couple seconds apart, but in some others it might be several hours, so keep that into consideration.
Hi Denis,
Many thanks for this. I am just familiarizing myself with the TeamCity API and it looks like it has almost everything I need for this.
Just to explain a little further, I am trying to do some housekeeping on our TeamCity instance and remove build configurations that are not being used or at least haven't been used recently (e.g. in the last 60 days)
So my pseudocode will be:
For each build type:
Get all the builds
if none of the builds have been triggered in the last 60 days then mark the Build Type as 'To Be Deleted'
Now, the above is fine if the build type has builds against it.
If it does not have any builds, is there a way of finding out when the build type itself was created?
For me, there is a BIG difference between deleting a build type that was created yesterday that has no-one has got around to building versus deleting a build type that was created 3 months ago and has never been built.
I don't see anything obvious in the API that indicates when a build type was created.
Thanks again for your help.
Sean
The audit contains this types of events. You can search for build_type_create* as the action and that could do the trick. You can find it at /app/rest/audit, more information here: https://www.jetbrains.com/help/teamcity/rest-api.html#RESTAPI-AuditRecords