How to make sure the subsequent jobs in azure pipeline pick up the same agent

Viewed 1979

How to make sure same agent is picked up in azure pipeline for the subsequent jobs?

I have a multiple job yaml pipeline in azure devops. There are multiple agents in the pool all the jobs uses the same pool. I am seeing an issue where the previous job is picking up the agent 1 and next job is picking up the agent 2. Is there any way to to restrict the pipeline to use the same agent for all the jobs in a pipeline?

1 Answers

You can use demands to specify what capabilities an agent must have to run your job. So, to make sure the subsequent jobs pick up the same agent you can specific the same agent as the demands for each job. Please see Agent pool jobs for details.

For example :

jobs:
- job: JobA
  timeoutInMinutes: 10
  pool: 
    name: Default
    demands: Agent.Name -equals PA0517
  steps:
  - bash: echo "JobA"

- job: JobB
  timeoutInMinutes: 10
  pool: 
    name: Default
    demands: Agent.Name -equals PA0517
  steps:
  - bash: echo "JobB"
Related