Team City Rest API - Getting running builds - teamcity

I'm trying to use the Team City rest api to get a list of the currently executing builds. It seems like it is only returning builds on the default branch and I would like to get the builds on all branches. This is the api call I'm using:
/teamcity/guestAuth/app/rest/builds?locator=running:true&branch:(default:any)

found the issue the url should be:
/teamcity/guestAuth/app/rest/builds?locator=running:true,branch:(default:any)

Related

Search a project in SonarQube based on the github Uri

I would like to search for a project's line coverage using the SonarQube Web API.
The entrypoint to my search is the github repository uri.
So something like this: git#github.com:user/my-project.git.
Currently, I am cutting out the repo name and try to find the project using /api/projects/index?search=my-project - assuming that the github repo name should be contained in the sonarqube project name.
I pick up the project key from the response and use it with /api/measures/component to retrieve the overall_line_coverage.
We are using the SonarQube gradle plugin to create the SonarQube project. We also set the sonar.branch property. So we end up with project keys like <groupId>:<artifactId>:<sonar.branch>.
Is there a better/more robust way to do this search - especially I would like to add the sonar.branch to the query the narrow down the search result.
go to your project homepage to get the project key OR use the internal (made public in 6.3) WS api/components/search with the q parameter
use the WS api/measures/component to retrieve your project measure

REST API for getting project last analysis date?

How do I get a project's last analysis time (the one you can see in the dashboard) with the REST API of SonarQube?
I am working with SonarQube 4.5.6, but if it's only available on later versions I'd still be interested in how it is done.
[EDIT] API relevant since SonarQube v6.3: api/project_analyses/search
[EDIT] Relevant API for SonarQube LTS v5.6.x: api/projects?versions=true
And since you mention later versions, since SonarQube 5.2:
api/ce/component : get the pending tasks, in-progress tasks and the last executed task of a given component (usually a project) (documentation)
P.S.: api/components/show can be used to get the component ID from the project key
P.S.2 : here's a real-life example on public SonarQube project. First get the component ID then query the component -> "submittedAt": "2016-03-07T06:04:31+0100" (slight difference with the dashboard value, due to the processing time on the scanner side)
You can use the Resources API : https://nemo.sonarqube.org/api/resources/index?metrics=date&format=json and look at the 'date' field to get the last analysis time.

How to get a list of active branches for a project using TeamCity REST API?

I am trying to find a list of all branches for a given project. Is it possible to get this information through Teamcity REST API? I found a different answer showing how to get a list of branches for a given build configuration:
Can you use the team city rest api to fetch plan branch names?
But this way I would have to run the query for all build configurations under given project.
However TeamCity has a concept of "active" branches on a given project. I am wondering if it is possible to fetch exactly that.
Actually, it is possible now.
Implemented for 2017.1 as an experimental features:
listing of the branches for a project (merged list of all project's build configuration's branches) via .../app/rest/projects/XXX/branches?locator=policy:XXX
additional branch node fields: "active", "lastActivity" timestamp, "builds" (with locator), available via "fields" parameter of the request
added "branches" into buildType node, available only via "fields" parameter of the request
Source: https://youtrack.jetbrains.com/issue/TW-44148#comment=27-2018515
I'm using exactly this url: http://TCSERVERADDRESS/app/rest/projects/PROJECTNAME/branches and it works good for me.
TeamCtiy REST API does not support showing active branches now. You are welcome to drop a feature request in the tracker

How can I use team city rest api to show only one build per branch for all branches in project?

I have multiple branches that are being tested under a single project and I'm currently using following command to show build statuses:
"/guestAuth/app/rest/builds?locator=project:<Project_Name>,running:any,branch:branched:any,count:20
Can limit the rest api to show just one build per branch?
Can you please be more specific? If you give us some example (e.g. "I have build configuration with builds A(steps a,b,c), B(steps d,e) , C(step f). A is from branch branch_A, B from branch_B" and so on so we have some clue how your setup looks like and what do you want to achieve.
You can check a permalinks for "latest successful build".
You can also ask for specific build status, not a whole project.

Using TeamCity build number in Buildmaster

Is it possible to grab the build number from TeamCity and use that as a build number in BuildMaster?
This could be done by triggering the BuildMaster API's Builds_CreateBuild method from TeamCity which accepts a numeric build number. It should be fairly straightforward to make a GET request to the BuildMaster JSON API from TeamCity, see this question for a simple way to do so: TeamCity Call Url Build Step
In order to create a new build including the build number you need to firstly enable the api under settings. There is no 'enable' button as such, you just need to provide an arbitrary key for the api authentication (any literal will do, but presumably make it complex for best security!).
The JSON syntax for the creating a build is as follows:
http://buildmaster-server/api/json/Builds_CreateBuild?API_Key=abcde12345&Build_Number=123&Release_Number=0.0
This will actually create a new build on your build master server. This can then be triggered via Team City using Powershell with the powershell script inline such as:
Invoke-WebRequest "http://buildmaster-server/api/json/Builds_CreateBuild?API_Key=abcde12345&Build_Number=%build.number%&Release_Number=0.0&Application_Id=2" -UseBasicParsing
You can add further variables and call hundreds of BuildMaster API's using the above method. Full API documentation can be found here: http://inedo.com/support/documentation/buildmaster/reference/api-methods

Resources