Getting all builds from a particular branch and project in the build queue using the REST Api?

Hi! 

I'm trying to automate canceling GitHub Merge Queue builds from the Team City build queue.

What I would like to do using if to list all build configs below a a certain top-level project that match a specific branch like gh-readonly-queue/main/pr-12-8beccaa9769c64337eb0bcfc7404febd33c3619c.

This doesn't seems possible with the BuildQueue rest api or am I mistaken?

I would like to use something like teamcity_url.com/app/rest/buildQueue?locator=buildType:(project:id:TopLevelProject,build:branch:gh-readonly-queue/main/pr-12-8beccaa9769c64337eb0bcfc7404febd33c3619c)' | jq

But this does not seem to work. First because project only applies to the exact project a build config is in and not up in the hierarchy and I have not gotten branch filtering to work at all.

Does someone have any examples of filtering the build queue by branch and top-level project?
 

0
3 comments
Hi,

BuildQueueLocator is different then the BuildLocator. Please refer to:
https://www.jetbrains.com/help/teamcity/rest/buildqueuelocator.html
https://www.jetbrains.com/help/teamcity/rest/buildlocator.html

There is no branch dimension for BuildQueue, as the BuildQueue entity is available as soon as the build is added to the queue.

And yes, you're correct, the project dimension stores only the parent project.

Best regards,
Anton
0

Sorry, but I have read the docs and I still don't understand these locators, neither does AI trying to use them.

Do you mean that even though I get branch as part of the response, is impossible to filter by that in any way?
Also no way to filter by project hiararchy? 

 

0
The locators are described in detail in https://www.jetbrains.com/help/teamcity/rest/locators.html
You can explore the available locator dimensions for the particular endpoint in the Autogenerated REST API Reference (for BuildQueue endpoint locator: https://www.jetbrains.com/help/teamcity/rest/buildqueuelocator.html) or by sending a request like GET /app/rest/buildQueue?locator=$help
As I mentioned, the BuildQueue endpoint locator doesn't have a branch dimension, so it can't be used to locate the build by the branch. The reason is that the BuildQueue entity is created as soon as the build is added to the queue, not when it's started.
The started builds have the Builds entity, and may be located and canceled using the Builds endpoint, as described in the documentation: https://www.jetbrains.com/help/teamcity/rest/start-and-cancel-builds.html#Cancel+Started+Build
The BuildLocator has branch dimension (https://www.jetbrains.com/help/teamcity/rest/buildlocator.html), so you can filter out the builds by the branch.

As for the parent project, both locators have buildType dimension, which is a BuildType locator: https://www.jetbrains.com/help/teamcity/rest/buildtypelocator.html
BuildType locator has project dimension, which is a ProjectLocator, representing a direct parent: https://www.jetbrains.com/help/teamcity/rest/projectlocator.html
As you can see from the link above, the ProjectLocator itself has project dimension, also representing a direct parent.
The locators can be nested as described here: https://www.jetbrains.com/help/teamcity/rest/locators.html#Nested+Locators
Therefore, it's possible to obtain the top project by nesting the locators, i.e., by filtering the buildType(s) that are children of project(s) that are children of project(s), and so on, until the top project is reached.

Best regards,
Anton
0

Please sign in to leave a comment.