2

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?

  • If they're separate jobs, the release is going to assume they can be run on separate agents. Perhaps you need to look into integrating them into a single job? Or integrate them a different way, by using pipeline artefacts to pass resources from one job to the next? – Vince Bowdren Oct 25 '19 at 08:58

1 Answers1

-1

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"
Andy Li-MSFT
  • 28,712
  • 2
  • 33
  • 55
  • @SubramanyaAdiga Have you resolved the issue by the answer? Any update here? – Andy Li-MSFT Nov 11 '19 at 13:45
  • 3
    I think the key to the original question is "subsequent" job. I take it to mean there's a dependency between the first job and the second job. Additionally, maybe we don't care which specific agent gets picked for the first job, but whatever it picked, the second\subsequent job must run on that same agent. – phandinhlan Jun 18 '20 at 18:42
  • 3
    Personally, this answer doesn't answer the question... if I have 3 agents with the same capabilities and the build picks #2 then all jobs in the chain need to run on #2... "capabilities" doesn't force THAT build to ALL run on #2 if all three agents have the capabilities. – WernerCD Jan 06 '21 at 14:35
  • It's a pity such a feature is not available. This just blocks a proper distribution along templates that hold stages or jobs. – kap Nov 30 '21 at 12:49
  • Yes its possible . see my answer here - https://stackoverflow.com/questions/70529025/is-there-a-way-to-force-the-use-of-the-same-agent-directory-for-all-jobs-inside/74884346#74884346 – Ritika Srivastava Misra Dec 22 '22 at 05:13