azure-devopsazure-devops-server-2019azure-devops-self-hosted-agent

run azuredevops task in all agents of the specified pool


Is there any way to make the pipelie task/job to run in all the agents of the agent pool ?

I am planning to create a release pipeline and scheduled once in every week, which is for cleaning up the build agents from unused docker images which are older than 3 months. so I got the command for the same and created one release pipeline with the "commandline" task with the command "docker image prune --all --filter "until=720h". But here we have multiple agents in the each pool and i have to ensure that this task is executed across all the agents in the specified pools. How can i Achieve this


Solution

  • You could create a pipeline with multiple Stages and run every stage on each agent.

    trigger:
    - main
    
    pool:
      vmImage: ubuntu-latest
    
    stages:
    - stage: agent1
      pool: 
       name: AgentPoolName
       demands:
        - agent.name -equals agent1
      jobs:
      - job: docker1
        steps:
        - script: docker image prune --all --filter "until=720h
    
    - stage: agent2
      pool: 
       name: AgentPoolName
       demands:
        - agent.name -equals agent2
      jobs:
      - job: docker2
        steps:
        - script: docker image prune --all --filter "until=720h