How to know whether a build is the last one on its build chain

Greetings,

I am developing a plugin that involves doing something after the last build of a build chain ends successfully. I have several build configurations with snapshot dependencies inside a project, and the next one runs automatically whenever the previous one is finished.


I am using the REST API route to retrieve snapshot dependencies (https://confluence.jetbrains.com/display/TCD10/REST+API#RESTAPI-Snapshotdependencies) and checking for the entire build chain whenever each build that's a part of it is finished, but I'm faced with a problem: The first build that runs, doesn't have any snapshot dependencies, so if I make the API call after the first build is finished, it won't return any meaningful results. Thusly, I won't know where it's placed in the build chain, and most importantly, if it's the last one.


One solution that I came up with was using the REST API, and each time a build ends, I would get its parent project, get every build from that project, and one by one get its snapshot dependencies to see if they depended on the build that had just finished. If no build had the present one on its snapshot dependencies, that would mean that it was the last build on the build chain. However that is slow and not very elegant.


Is there a simpler way, using either the REST API or the Java API, to know if a certain build is the last on the build chain? Or to get the entire build chain on a per-build basis? I'm open to anything.

Thank you in advance,

João

1 comment
Comment actions Permalink
Official comment

Hello João,

Actually, request like .../app/rest/builds?locator=snapshotDependency:(from:(id:XXXX),includeInitial:true),defaultFilter:false should return all any builds which have snapshot dependency on the build with id XXXX.

What is does not return is whether there can be builds in the future depending on the current build. You can check the build configuration settings to find the build configurations which have a snapshot dependency on the current one so that there can be builds in the future which epend on the current one. That can be achieved with a request like  .../app/rest/buildTypes?locator=snapshotDependency:(from:(build:(id:XXXX)),includeInitial:true)

However, the entire goal of finding "the last one in the build chain" seems to be quite fragile: there can be several "last ones", they can change over time and unknowingly affecting your logic, etc. I'd consider other approaches to your task, like explicitly marking the build configurations you are interested in.

Please sign in to leave a comment.