1

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

Vowneee
  • 956
  • 10
  • 33
  • You could add this functionality as a cron task if you have a linux machine or a scheduled task if you have a windows machine. – GeralexGR Apr 27 '22 at 07:01
  • but again that will be a manual task to set across all the build agents. Looking for a way to achieve this from the ADO pipeline side itself – Vowneee Apr 27 '22 at 07:07

2 Answers2

3

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
GeralexGR
  • 2,973
  • 6
  • 24
  • 33
  • Nice, but howto get a dynamic list of agents from a transient pool? Also a "docker system prune" might be more effective – krad Aug 25 '22 at 09:13
1

While @GeralexGR's answer works and I've gone that route in the past, it can get really annoying once you try to scale up your environment.

That's why I switched to deployment groups for "agent management". Obviously you will need to install another agent on every machine. But that can also be an advantage: the ratio of Servers to agents doesn't have to be 1:1, we run multiple agents per machine therefore if I were to list every agent in this case docker would prune everything twice.

With deployment groups you only need to add the agent (1 per machine) to the group and all pipelines "maintaining" that group of agents will automatically target that machine as well for future runs. The main disadvantage in my opinion is, that you cannot use deployment groups in yaml (yet?!). So you need to use the GUI to configure deployment group tasks in the release pipelines.

Jakob
  • 11
  • 4