I have agents pool that have different user capabilities (user paremeters). Also I have pipelines which contain different demands for agents. In other words, it is not possible to run pipeline in all agents.
How to find out which agents are suitable for running the pipeline?
How to check the possibility of running a pipeline on an agent?
I can get data (contains capabilities/paremeters) about agents using query: https://dev.azure.com/{organization}/_apis/distributedtask/pools/{poolId}/agents?includeCapabilities=true
I can find out the data (demands) of manual-pipelines (pipelines created manually by users) using query:
https://dev.azure.com/{organization}/{project}/_apis/build/definitions/{definitionId}
But how to get the requirements of pipelines created using yaml files?
Unfortunately, I did not find an answer to my question.
CodePudding user response:
Demands and capabilities are designed for use with self-hosted agents so that jobs can be matched with an agent that meets the requirements of the job. Please see the doc for more details: https://learn.microsoft.com/en-us/azure/devops/pipelines/process/demands?view=azure-devops&tabs=yaml
So, when you set demands for the pipelines, it will automatically check and be assigned to a suitable agent randomly.
But if for some reasons you want to see the list of agents.
Then please see the following idea to help to get the suitable agents for a pipeline.
1.Use the rest api https://dev.azure.com/{organization}/{project}/_apis/build/definitions/{definitionId}
to get the demands of the manual pipeline.
Here if I set it as
demands:
- user1
- user2
2.Use the rest api 'https://dev.azure.com/{organization}/_apis/distributedtask/pools/{poolId}/agents?includeCapabilities=true&demands=user2,user1&api-version=6.0'to get agents that is suitable for the pieline run. enter image description here
But if it is not your issue, please kindly clarify and if you could explain the purpose of doing so, that would be good.
Thanks
CodePudding user response:
Try below steps:
- Get the yaml file name with the rest API:
https://dev.azure.com/{org-name}/{Project-name}/_apis/build/definitions/{definitionId}
- Get the yaml file content using the name we get from last step:
https://dev.azure.com/{org-name}/_apis/git/repositories/{repositoriesId}/Items?path=/{yaml-file-name}.yml&api-version=7.1-preview.1
The result should be the whole content of the YAML file, you can see the demands in the file content.