azure-devopsazure-devops-self-hosted-agent

Prevent Azure Pipelines from failing build: No Agent Found in Pool which satisfies demand


I have a self-hosted pool of build agents for Azure Pipelines.

My build servers are hosted in AWS and I use an ASG the uses an SQS queue to scale out as build jobs are needed. If no jobs needed - I scale down to zero.

The problem I am running into is I run both windows and linux agents. I have implemented my pipelines.yml file with conditions for the various tasks depending on the OS. i.e.

          - task: AWSPowerShellModuleScript@1
            displayName: Deploy Stack
            inputs:
              workingDirectory: $(Build.SourcesDirectory)/stack
              awsCredentials: my-creds
              regionName: $(region)
              scriptType: inline
              inlineScript: cdk deploy --require-approval never
            condition: eq(variables['Agent.OS'], 'Windows')

          - task: AWSShellScript@1
            displayName:  Deploy Stack
            inputs:
              awsCredentials: my-creds
              regionName: $(region)
              scriptType: inline
              inlineScript: |
                aws cloudformation deploy --my-stack --template-file template.yml \
                --capabilities CAPABILITY_NAMED_IAM
            condition: eq(variables['Agent.OS'], 'Linux')

The problem is my build fails immediately if there is not an agent that has all of the demands available. For me this happens to be "sh".

It will take a few minutes for the instance to spin up and register with Azure Dev Ops if no jobs had been run in awhile and the ASG has terminated all instances.

I tried using the

timeoutInMinutes: 15 

on the job - but that still fails:

##[error]No agent found in pool MYPOOL which satisfies the following demand: sh. All demands: DotNetFramework, sh, Agent.Version -gtVersion 2.163.1

Is there anyway to ignore this error or allow for a period of time until an agent becomes available?


Solution

  • My build servers are hosted in AWS and I use an ASG the uses an SQS queue to scale out as build jobs are needed. If no jobs needed - I scale down to zero.

    You must ensure there is at least one build agent available in the agent pool otherwise the builds will fail immediately.

    To allow scaling to zero and create agents on-demand, consider adding a dummy agent which is offline/disabled. That will prevent the no agent found error.

    Dummy agent