'Azure pipeline condition to choose trough agent

I would like to insert a condition in my pipeline, specifically I would like the swich pipeline from the default agent to the custom one when I get an error, ho to insert this condition in pipeline? NB: I have just created and installed my custom agent on private VM in azure

eg this is my azure-pipelines.yml file:

trigger:
- feature/test_pipeline


**how to insert an 'if condition' to choose different agent
if default is not available or get error** 

pool:
  vmImage: ubuntu-latest

steps:

- script: |
    echo "my power script"
  displayName: 'Run script' ```


Solution 1:[1]

Azure pipeline condition to choose trough agent

I am afraid there is no such way to do this at this moment.

As we know, the YAML files are precompiled when we execute our pipeline. During the pre-compilation phase, the YAML will be parsed to determine whether there are syntax or logical errors.

However, if you do not enter the compilation and execution stage, you cannot know the state of the agent.

Therefore, it is impossible to judge the state of the agent in the pre-compilation stage.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Leo Liu-MSFT