With a higher usage of our build agents in Azure DevOps, we run out of disk space twice in the same week. It was now time to find a solution that would declutter our local build agents.
The last time I searched for a solution I could not find anything that would allow me to clean up the working directory of a build agent without creating a solution by myself. Luckily, Microsoft listened to the countless complaints and created a solution directly in the build agent pool of Azure DevOps.
In the Organization Settings go to Agent pools and select your pool. On the pool you now find a Settings section where you can activate the maintenance jobs:
You can set how many days the unused working directories in your build agents are kept around and when your maintenance job should run:
Once activated, the maintenance job will run on all agents and remove the no longer needed working directories.
This simple solution solved our disk space problems and saved us a lot of manual clean-up time. I highly recommend activating the maintenance jobs, even if you do not run out of disk space (yet).