I have two questions.
Is there any method to check self hosted agent on Azure VM is busy in running azure pipeline.
and if there is any method available then can we shift that Azure pipeline from self hosted agent to Microsoft Hosted Agent, so that we can use that self hosted agent for other pipeline.
1,You can check the status of self hosted agent directly from Azure Devops UI.
Go the Project Settings--> Agent Pools under Pipelines-->Select the Agent Pool in which the self hosted agent resides--> Click Agents tab of the Agent Pool page--> You will see the current status of each agents. See below screenshot.

2, To shift Azure pipeline from self hosted agent to Microsoft Hosted Agent. Currently you have to manually shift the agent pool/agent from the pipeline definition, so that the pipeline will target a differnt agent pool/agent.
Go the pipeline edit page--> Click Pipeline-->Change the agent pool from the Agent Pool dropdown list. see below screenshot.

Each agent job in the pipeline can select its own agent pool. You can change the agent pool from the agent job's configuration page. see below screenshot.
Noted: the agent pool selected for the Agent job will override the agent pool selected for the Pipeline mentioned in above screenshot.

You need to manually change the pool value in the YAML file. For below example. see document here for more information.
Yaml pipelines also support select agent pool at runtime using runtime parameter. see document here for more information.
pool:
vmImage: ubuntu-16.04
You can use REST API to get list of agents:
GET https://dev.azure.com/{organization}/_apis/distributedtask/pools/{poolId}/agents?api-version=5.1
You will find there:
based on this you can easily figure out if your agent is busy or not.
And for your second question. This is not possible at the moment. Please check this two topics:
Please upvote community request to increase a chance of having this implemented!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With