Azure DevOps Maintenance Jobs: How to Automate Agent Pool Cleanup

Learn how to configure maintenance jobs in Azure DevOps to keep your self-hosted agent pools clean, efficient, and running smoothly.

Azure DevOps Maintenance Jobs: How to Automate Agent Pool Cleanup
Photo by BoliviaInteligente / Unsplash

Imagine your self-hosted Azure DevOps agents as a team of hardworking robots. They build, test, and deploy your code day in and day out—no coffee breaks, no complaints. But just like your laptop after months of downloads, they start to slow down, cluttered with old files, cached data, and forgotten artifacts.

Enter Azure DevOps Maintenance Jobs: the automated cleanup crew that keeps your agents running like they just rolled off the assembly line. No more manual deletions, no more "why is my pipeline failing?" mysteries—just smooth, efficient automation.

In this guide, we’ll walk through:

  • What Azure DevOps is and why it’s a developer’s best friend
  • The lowdown on agent pools, pipelines, and releases
  • Self-hosted agents: the good, the bad, and the "why did my disk fill up?"
  • A step-by-step guide to setting up maintenance jobs
  • Why this tiny feature is a game-changer for your CI/CD workflow

Ready to give your agents the TLC they deserve? Let’s get started!

What Is Azure DevOps?

Azure DevOps is Microsoft’s all-in-one platform for planning, developing, testing, and deploying software. It combines:

  • Repos (Git repositories)
  • Pipelines (CI/CD automation)
  • Boards (Agile project management)
  • Test Plans (manual and automated testing)
  • Artifacts (package management)

Whether you’re a solo developer or part of a large enterprise, Azure DevOps helps streamline workflows, reduce manual errors, and speed up releases.

What Are Agent Pools, Pipelines, and Releases?

Agent Pools

An agent pool is a collection of machines (agents) that execute jobs in your pipelines. Azure DevOps offers two types:

  • Microsoft-hosted agents (managed by Azure, no maintenance required)
  • Self-hosted agents (run on your own infrastructure, giving you full control)

Pipelines & Releases

  • Pipelines automate builds, tests, and deployments.
  • Releases manage the deployment of your application across different environments (dev, staging, production).

Self-hosted agents are great for customization but require manual maintenance—unless you set up maintenance jobs!

Self-Hosted Agents: Pros & Cons

Pros

  • Full control over hardware, software, and security
  • Cost-effective for long-running or high-frequency jobs
  • Custom environments (specific tools, dependencies, or configurations)

Cons

  • Maintenance overhead (updates, cleanup, monitoring)
  • Risk of clutter (old jobs, cached files, disk space issues)
  • Manual intervention required if not automated

Solution? Maintenance jobs!

How to Configure Maintenance Jobs in Azure DevOps

Maintenance jobs help automatically clean up old jobs, free disk space, and keep agents running efficiently. Here’s how to set them up:

Step-by-Step Guide

Go to Organization Settings. From your Azure DevOps home page, click on Organization settings on the bottom left corner.

Navigate to Agent Pools. Under Pipelines, select Agent pools.

Choose the pool you want to configure (e.g., Default) then click the Settings tab at the top.

Toggle Enable maintenance jobs to On.

Configure the Schedule

    • Set the frequency (daily, weekly, custom).
    • Define retention policies (e.g., delete jobs older than 30 days).

Don't forget to Save at the end.

Why Maintenance Jobs Are a Game-Changer

  • Prevents disk space issues (no more failed jobs due to full storage!)
  • Reduces manual cleanup (set it and forget it)
  • Improves agent performance (faster builds, fewer errors)
  • Enhances security (removes old, potentially vulnerable files)

Final Thoughts

Self-hosted agents give you power, but with great power comes great responsibility. Maintenance jobs are your secret weapon to keep things running smoothly without the hassle.