12.3 Artifact & Build Retention Governance
Key Takeaways
- Project-level pipeline retention sets days to keep runs, with a default of 30 days and a configurable range of 1 to 730 days.
- Artifacts, test results and symbols can be retained for shorter periods than the run record itself, keeping history without keeping payloads.
- A retention lease pins a specific run beyond the policy, which is how a compliance hold or a currently deployed release is protected from cleanup.
- Runs deployed to an environment can be retained automatically so the artifact behind a live deployment always remains available for rollback.
- A seven-year regulatory obligation is 2,555 days, which exceeds the 730-day policy maximum and therefore requires a lease or an external archive.
12.3 Artifact & Build Retention Governance
Optimization decides how fast a pipeline runs; retention decides how long its output survives. Retention policy is where storage cost meets audit obligation, and Azure DevOps separates the run record, the artifacts, the test results and the symbols so each can be kept for a different period.
1. Artifact and Build Retention Governance
Continuous delivery produces massive quantities of pipeline execution logs, published drop artifacts, symbols, and test attachments. Without automated retention governance, storage consumption escalates costs and exposes organizations to compliance risks.
The Modern Project-Level Retention Model
In modern Azure DevOps, retention policies are managed at the Project Settings level rather than configured individually on each pipeline:
- Navigate to Project Settings → Pipelines → Settings.
- Days to keep runs: Specifies how many days pipeline run history, logs, and test results are retained (Default: 30 days; Range: 1 to 730 days).
- Minimum runs to keep per pipeline: Guarantees that at least $N$ successful runs are preserved regardless of age, ensuring low-frequency pipelines do not lose their baseline history.
- Days to keep pull request runs: Typically configured for a shorter period (e.g., 7 to 10 days) since PR branches are short-lived.
Artifacts vs. Test Results vs. Symbols Retention
┌─────────────────────────────────────────────────────────────────────────────────┐
│ RETENTION CATEGORIES IN AZURE PIPELINES │
├──────────────────────┬──────────────────────────────────────────────────────────┤
│ Data Category │ Retention Mechanics & Governance │
├──────────────────────┼──────────────────────────────────────────────────────────┤
│ Pipeline Artifacts │ Dropped zips/binaries published via PublishPipelineArtifact│
│ (Build Drops) │ Deleted when the pipeline run expires. Can set specific │
│ │ retention per artifact or inherit run lifecycle. │
├──────────────────────┼──────────────────────────────────────────────────────────┤
│ Test Results & TRX │ Stored in Azure Test Plans analytics data store. │
│ Files │ Governed by project retention settings; aggregated data │
│ │ preserved for long-term reporting. │
├──────────────────────┼──────────────────────────────────────────────────────────┤
│ Symbol Files (PDBs) │ Published via IndexSourcesAndPublishSymbols@2 to Azure │
│ │ DevOps Symbol Server. Configured with an independent │
│ │ expiration window to support post-mortem debugging. │
├──────────────────────┼──────────────────────────────────────────────────────────┤
│ Azure Artifacts │ NuGet, npm, Maven feeds governed by Feed Retention │
│ (Package Feeds) │ Policies: maximum versions per package (e.g., retain 10).│
└──────────────────────┴──────────────────────────────────────────────────────────┘
Pipeline Retention Leases
What happens when a build is deployed to Production and must be retained for 7 years to satisfy regulatory audits (e.g., SOX, HIPAA, or PCI-DSS)?
[Pipeline Run #4128 Executes]
│
▼
[Deploys to Environment: 'Production']
│
▼
[Azure Pipelines Creates Automated RETENTION LEASE]
│
┌─────────┴─────────┐
▼ ▼
[30-Day Project [Retention Lease ACTIVE]
Retention Policy] • Prevents automated deletion
Attempts Cleanup • Retains build run, logs, and drop artifacts
• Preserved until lease is explicitly removed
- Automated Retention Leases on Environments: When a pipeline executes a deployment job targeting an Azure DevOps Environment (e.g.,
environment: 'Production'), Azure Pipelines automatically attaches a retention lease to that specific pipeline run. - Lease Protection: A pipeline run protected by an active retention lease will never be deleted by the automated retention cleanup, even if it exceeds the 30-day project retention setting.
- Manual & REST API Leases: Compliance officers or automation scripts can programmatically create retention leases via the Azure DevOps REST API:
POST https://dev.azure.com/{organization}/{project}/_apis/build/retention/leases?api-version=7.1-preview.1 Content-Type: application/json [ { "buildId": 4128, "daysValid": 2555, "definitionId": 12, "ownerId": "ComplianceAuditOfficer", "protectPipeline": true } ]
2. Comprehensive Optimization Techniques Comparison Table
| Technique | Primary Mechanism | Best Applied To | Storage Impact |
|---|---|---|---|
Pipeline Caching (Cache@2) | Tarball stored in Azure DevOps blob store restored via key hash | npm, NuGet, pip dependencies, compiler cache (ccache) | Deduplicated cloud storage; 10 GB limit per cache |
Pipeline Artifacts (PublishPipelineArtifact@1) | Optimized chunked file deduplication service | Passing build outputs between stages | Counted against project pipeline artifact storage |
| Custom VMSS Golden Images | Pre-baking tools and packages into OS VHD via Packer | Huge toolsets, static libraries, runtime SDKs | Managed disk storage in Azure subscription |
| Parallel Test Slicing | Dividing test assemblies across $N$ parallel agent jobs | Large integration and UI test suites (> 30 min) | No extra storage; consumes concurrent parallel jobs |
Shallow Clone (fetchDepth: 1) | Fetching only HEAD commit from Git | Large monorepos with extensive git history | Reduces agent disk space and network bandwidth |
3. Realistic Exam Scenario & Common Traps
Scenario: Global Healthcare SaaS Compliance & Speed Optimization
Context: MedTech Cloud builds a HIPAA-compliant healthcare portal. The multi-stage pipeline currently takes 55 minutes to execute:
- Dependency installation (
npm cianddotnet restore) takes 12 minutes on every run. - The 3,500 integration tests take 35 minutes running sequentially on a single Linux agent.
- HIPAA regulations mandate that every build artifact and test execution log deployed to the
Production-HIPAAenvironment must be retained for exactly 7 years (2,555 days). - Routine feature branch validation builds must be deleted after 14 days to prevent storage cost escalation.
DevOps Solution:
- Optimization: Implement the
Cache@2task for bothnpm(package-lock.jsonkey) andNuGet(packages.lock.jsonkey), reducing dependency resolution from 12 minutes to 45 seconds. - Parallelization: Configure
strategy: parallel: 5on the test job and configureVSTest@2test slicing, reducing the 35-minute test phase to approximately 7 minutes. - Retention Governance: Configure Project Settings pipeline retention to 14 days for standard runs. Configure the deployment stage using a
deployment:job targeting theProduction-HIPAAenvironment. Azure Pipelines automatically creates an environment retention lease, and an automated REST call or environment retention policy sets the lease duration to 2,555 days.
Common Exam Traps to Avoid
- Trap: Caching Dynamic or Volatile Output Folders: Caching folders containing build timestamps or volatile binaries without hashing their inputs results in stale, unrepeatable builds.
- Trap: Believing
Cache@2Saves on Failure: The cache upload occurs in a post-job step that runs only if the job succeeds. If tests fail, the cache is not saved, ensuring that corrupted states are not cached. - Trap: Confusing Project Retention with Azure Artifacts Feed Retention: Project retention settings govern pipeline runs, logs, and pipeline artifacts. Package feeds in Azure Artifacts (NuGet/npm feeds) have their own independent Feed Retention Policies governing package versions.
An enterprise engineering organization subject to regulatory compliance (SOX and HIPAA) must retain all pipeline run history, diagnostic logs, and published deployment artifacts for builds deployed to the Production environment for a minimum of 7 years (2,555 days). Standard development builds should be purged after 30 days to minimize storage costs. How should the DevOps architect configure this retention requirement in Azure DevOps?