Reclaim disk space early in Azure DevOps pipelines running on Microsoft-hosted Ubuntu agents.
The task removes large preinstalled toolchains that are often unnecessary for Docker and application builds:
- Android SDK:
/usr/local/lib/android
- GHC/Haskell:
/opt/ghc
- Boost:
/usr/local/share/boost
After cleanup, the task prints df -h / to the pipeline log so the remaining root filesystem capacity is visible.
Usage
- task: RemoveUnusedAgentTools@1
displayName: Remove unused agent tools
All three tools are selected by default, so the minimal task above removes Android SDK, GHC, and Boost. Use the task editor checkboxes or YAML inputs to keep selected toolchains:
- task: RemoveUnusedAgentTools@1
displayName: Remove unused agent tools
inputs:
removeAndroidSdk: true
removeGhc: false
removeBoost: true
The available boolean inputs are removeAndroidSdk, removeGhc, and removeBoost. The task succeeds when one or more selected target directories are already absent and fails only when command execution encounters an unexpected error.
Do not leave an empty inputs: key in YAML. Use the minimal form without inputs, or include at least one input value. The task editor writes the three required checkbox values when generating YAML.
Add other Linux directories one per line:
- task: RemoveUnusedAgentTools@1
displayName: Remove unused agent tools
inputs:
additionalDirectories: |
/opt/custom-sdk
/usr/local/share/custom-cache
The task logs the selected directories and a readable equivalent command before removal. Azure DevOps keeps custom task implementations inside the extension, so a task: entry is not expanded into an inline script: block.
Commands
sudo runs the removal with elevated permissions.
rm -rf removes directories recursively without prompting and accepts paths that are already absent.
-- ends command options, so configured values are treated as paths.
df -h / prints human-readable root filesystem usage and does not remove anything.
Absolute paths are used as written. Relative paths, such as test/adam, are resolved under $(Build.SourcesDirectory) and cannot escape the checkout through ... The root directory / is rejected. Values are passed as command arguments and are not interpreted as shell code.
Requirements
Use the task on a Linux agent with Bash and passwordless sudo, such as a Microsoft-hosted Ubuntu agent. The listed directories are permanently removed from the current pipeline agent for the duration of the job.