Designing a Retention Strategy for Artifacts and Dependencies
This lesson explains how to keep what matters and remove the rest.
Learning outcomes
After completing this lesson, you will be able to:
- Explain the needs that drive retention.
- Describe retention settings and leases in Azure Pipelines.
- Set retention in GitHub Actions.
- Apply retention to packages and images.
What drives retention
Retention balances three needs. Audit and compliance may require records of what was deployed, and when. Operations needs recent artifacts for rollback and debugging. Cost pushes the other way, because storage is billed, and old data has little value. A strategy treats each kind of data according to its purpose, instead of applying one long period to all of it.
Retention in Azure Pipelines
Retention is set under Project settings > Pipelines > Settings. The settings apply to the whole project, as Azure DevOps no longer supports retention rules per pipeline. They cover the days to keep artifacts, symbols and attachments, the days to keep runs, the days to keep pull request runs, and the number of recent runs to keep for each pipeline. In most projects the defaults are 30 days for runs and artifacts, 10 days for pull request runs, and three recent runs. Policies are processed once a day.
Retention leases
A retention lease keeps a specific run beyond those limits, which suits something like a production release. A run can be retained manually from its menu, and deployments to environments can be retained. A pipeline can also create a lease through the REST API, for a set duration.
- script: |
curl -s -X POST \
-H "Authorization: Bearer $SYSTEM_ACCESSTOKEN" \
-H "Content-Type: application/json" \
-d "[{\"daysValid\":365,\"definitionId\":$(System.DefinitionId),\"ownerId\":\"User:$(Build.RequestedForId)\",\"protectPipeline\":false,\"runId\":$(Build.BuildId)}]" \
"$(System.CollectionUri)$(System.TeamProject)/_apis/build/retention/leases?api-version=7.1"
displayName: Keep this production release for a year
env:
SYSTEM_ACCESSTOKEN: $(System.AccessToken)This approach keeps long retention for the small number of runs that need it, while the project's general settings stay short. Raising retention for everything would be far more expensive.
The following diagram shows how long each kind of pipeline run is kept for a regulated company.

Retention settings and leases
Retention in GitHub Actions
GitHub keeps workflow artifacts and logs for 90 days by default on most plans. The period can be set at repository, organization or enterprise level, within a maximum. A single artifact can have a shorter period with retention-days.
- uses: actions/upload-artifact@v4
with:
name: test-report
path: reports/
retention-days: 7Artifacts count towards a plan's storage allowance, which is shared with GitHub Packages, so deleting them promptly reduces cost. Important outputs that must last, such as a release binary, should be attached to a GitHub release, or published to a package registry. Caches are evicted automatically when unused.
Retention in GitHub
Retention for packages and dependencies
Azure Artifacts feeds have their own retention policies, which limit the number of versions kept for each package, and delete old versions automatically. Versions promoted to a view are protected, as are those downloaded recently, so a policy does not remove a version still in use. This protects the 2 GiB free allowance.
Azure Container Registry has a retention policy for untagged manifests, in the Premium tier, and az acr purge can run as a scheduled task to delete old images by age and name pattern. GitHub Packages keeps versions until they are deleted, and a workflow can remove old versions.
The following table shows a typical strategy.
| Item | Suggested retention | Mechanism |
|---|---|---|
| Pull request run logs | Days | Project setting, or retention-days |
| Main branch artifacts | Weeks | Project setting |
| Production release artifacts | As long as support or audit requires | Retention lease, or GitHub release |
| Package versions | A set number per package | Feed retention policy |
| Container images | Current and recent versions | az acr purge, or a retention policy |
| Audit data | As policy requires | Export to Azure Monitor Logs |
Retention for each kind of output
Keeping production builds
A regulated company must keep artifacts from each production deployment for seven years, but it wants all other runs removed after 30 days. Azure Pipelines project retention is 30 days. What should you do?
Keep the 30-day project setting, and create a retention lease as part of the production deployment, or copy artifacts to a long-term store such as Azure Blob Storage with an immutability policy. Raising the project setting to seven years would retain everything and raise cost. Per-pipeline retention rules are no longer supported, so they are not an option.
Can one pipeline have longer retention through its own rule?
Show answer
No. Per-pipeline rules are no longer supported, so use a retention lease for specific runs.
Exam Tips
Remember for the exam
- Retention settings in Azure Pipelines apply at project level.
- A retention lease keeps a specific run for longer.
- GitHub artifacts default to 90 days; retention-days shortens one artifact.
- Feed retention policies protect versions in views.
- Use az acr purge for scheduled clean-up of images.