1
votes

Our developer teams produce many NuGet packages which are published to Azure DevOps Artifacts feed. Most of them become unwanted over a week or two.

How can I select which artifacts should be covered with retention? Azure provides only general configuration, basically allowing only to specify a time after which artifacts will be retained. I was thinking about some sort of job which would select artifacts that match my criteria and delete them, but I'm afraid Azure DevOps REST API does not provide such functionality as Artifact deletion.

For example, I'd like to cover all pre-release packages with retention policy.

You can check your artifacts storage here (mind the placeholder) https://dev.azure.com/<org>/_settings/storage

Retention policies overview https://docs.microsoft.com/en-us/azure/devops/pipelines/policies/retention?view=azure-devops&tabs=yaml

Artifacts how-to https://docs.microsoft.com/en-us/azure/devops/artifacts/how-to/delete-and-recover-packages?view=azure-devops&tabs=maven

Artifacts docs at Azure DevOps REST API https://docs.microsoft.com/en-us/rest/api/azure/devops/build/artifacts/get%20artifact?view=azure-devops-rest-5.1#artifactresource

1

1 Answers

2
votes

The rest api you mentioned in the question is about build artifacts, the artifacts are the files that you want your build to produce. Please refer to this document.

I think what you actually need is Delete Feed rest api. This rest api can remove a feed and all its packages. Note: The action does not result in packages moving to the RecycleBin and is not reversible.

DELETE https://feeds.dev.azure.com/{organization}/{project}/_apis/packaging/feeds/{feedId}?api-version=5.1-preview.1

To delete a package ,you can use NuGet - Delete Package Version rest api. Send a package version from the feed to its paired recycle bin.

DELETE https://pkgs.dev.azure.com/{organization}/{project}/_apis/packaging/feeds/{feedId}/nuget/packages/{packageName}/versions/{packageVersion}?api-version=5.1-preview.1