We are using Azure DevOps / Pipelines for build and release management in our team.
I wanted to have a quick look if the hosted build agent is currently free or in use, so I have created a Visual Studio Code Extension to display the info in the status bar.
- To get started you create a new project with yeoman:
- The docs are really helpful.
- There are a lot of samples for the different use cases here
The source of my extension can be found here in my GitHub repo
To connect to the Azure DevOps REST API you need a personal access token, which can be obtained from https://dev.azure.com/YOUR_ORG -> Your Account -> Security
The API documentation can be found here.
The specific API I wanted to use is missing in the documentation which maybe means it is not for public use (yet?). However the DevOps portal is using the same API so it works for now:
The parameters are important to see all the running tasks from the hosted agents. The result contains a variable
usedCount with the number of currently running jobs. However to get the details who is building what you need a second call to the details API, which comes back as a result from the first call. See here:
To access the REST API you have to use BASIC auth with a dummy username and the PAT (personal access token) as the password as you can see here (I’m using the request HTTP client library to call the API).