Azure Pipelines Cache@2 task interaction with self‑hosted agents and stale cache handling
0 reputation · 11 Jan 2024, 13:16 UTC
The goal is to guarantee that any change to a file that influences the build—such as a version file stored outside the cached directories—forces the Cache@2 task to treat the cache as missed, thereby preventing the reuse of stale data that could produce non‑deterministic builds.
On Microsoft‑hosted agents the cache is automatically removed after seven days of inactivity, while self‑hosted agents retain caches until the folder is manually deleted or the agent is re‑imaged. Because the Cache@2 task derives its key solely from user‑supplied inputs and does not perform content‑based hashing, a modification to an uncached file will not generate a new key unless the pipeline author updates the key or restore key manually, leaving the behavior of stale cache reuse unresolved.
- What strategies can be employed to automatically incorporate version‑file changes into the cache key without altering the pipeline YAML each time?
- How can teams enforce cache invalidation on self‑hosted agents when uncached inputs change, given the lack of built‑in content hashing?
- Is there a recommended cleanup policy or automated process that balances cache reuse benefits with the risk of stale entries on long‑running self‑hosted agents?