thisJUSTin816
thisJUSTin816

Reputation: 31

Is there a way to increase or decrease the amount of purchased parallel jobs via API

Since Azure DevOps doesn't support auto-scaling of the MS hosted agents, I would like to be able to adjust it via automation. But I can't find any APIs that enable adjusting the paid parallel jobs for MS hosted agents. Does it exist?

Screenshot of the parallel jobs billing section

I know that I could spin up an Azure VM Scale Set, but the hosted agents are much cheaper, and I don't need to maintain the hosted agents so I would like to take advantage of them if possible.

I've reviewed the Azure DevOps API documentation. I've also tried to grab the API from the network tab in dev tools which gave me https://azdevopscommerce.dev.azure.com/[GUID]/_apis/AzComm/MeterResource but I get an unauthorized error when using the same headers as other Azure DevOps APIs.

Upvotes: 3

Views: 322

Answers (2)

angularsen
angularsen

Reputation: 8668

Azure recently launched Managed DevOps Pools that can help save costs or speed up builds.

  • Define your own VM size and OS image to use, to speed up builds with extra cpu, memory, gpu etc.
  • Set a max concurrency limit for automatically spinning up agents on demand
  • Set schedule for having X available agents, to avoid cold start of 5-15 minutes
  • Supports stateful agents
    • Grace period allows reusing agent for a warm start, if a new build is queued within a given time, good for bursts of build jobs
    • You may need to clean up content from previous build

Note: Does not yet suport MacOS agents, so for MAUI apps targeting Mac, Android, iOS, you still need to ues Microsoft hosted pool.

Upvotes: 0

Stefan K.
Stefan K.

Reputation: 63

I had the same problem and was able to change the amount of purchased parallel jobs using the REST API.

I stumbled accross this powershell gallery, which helped me a lot: https://www.powershellgallery.com/packages/VSTeam/7.2.0/Content/vsteam.functions.ps1

First of all you need to get a valid token for performing the request. You can get this token using a PAT from your Azure DevOps organization:

curl -X POST -H "Content-Type: application/json" \
--data '{ "namedTokenId" : "AzCommDeploymentProfile" }' \
-u 'user:<PAT>' \
https://dev.azure.com/<org_name>/_apis/WebPlatformAuth/SessionToken?api-version=7.2-preview.1

As you are using a PAT, the username in the request above is arbitrary

The response contains a bearer token. As you already found out, the api url is https://azdevopscommerce.dev.azure.com/[GUID]/_apis/AzComm/MeterResource

I used the following request for changing the number of self hosted agents:

curl -X PATCH -H "Content-Type: application/json" \
-H "Authorization: Bearer <token>" \
--data '{ "meterId": "f44a67f2-53ae-4044-bd58-1c8aca386b98", "purchaseQuantity": 5 }' \
https://azdevopscommerce.dev.azure.com/<org_id>/_apis/AzComm/MeterResource?api-version=7.2-preview.1

If the information in the powershell gallery is still correct, the meter id for microsoft hosted agents is 4bad9897-8d87-43bb-80be-5e6e8fefa3de

Upvotes: 2

Related Questions