Skip to main content

Cleanup Policies API

These REST API endpoints are used to manage cleanup policies to Nexus Repository. The user needs access to read and edit the nexus:settings permissions.

Assigning cleanup policies will require the use of the Repositories API.

Note

Only available in Sonatype Nexus Repository Pro. Interested in a free trial? Start here.

Request returns a list of cleanup policies. The user requires the following permissions: (nexus:settings.read)

GET /service/rest/v1/cleanup-policies

Example

curl -u admin:admin123 -X GET http://localhost:8081/service/rest/v1/cleanup-policies

Example response

[
  {
    "notes": "",
    "criteriaLastBlobUpdated": null,
    "criteriaLastDownloaded": null,
    "criteriaReleaseType": null,
    "crtieriaAsserRegex": ".*",
    "retain": null,
    "name": "test-cleanup",
    "format": "maven2",
  }
]

Required permissions (nexus:settings.read)

GET /service/rest/v1/cleanup-policies/{name}
  • name - User created name for the cleanup policy

Example

curl -u admin:admin123 -X GET http://localhost:8081/service/rest/v1/cleanup-policies/test-cleanup

See the GET Cleanup Policy example for the response.

The user requires the following permissions: (nexus:settings.edit) The request to add a new cleanup policy is submitted in the body of a POST request. The endpoint will return a 201 when successful and a 409 when the name already exists.

POST /service/rest/v1/cleanup-policies
{
  "notes": "string",
  "criteriaLastBlobUpdated": 0,
  "criteriaLastDownloaded": 0,
  "criteriaReleaseType": "RELEASES",
  "criteriaAssetRegex": "string",
  "retain": null,
  "name": "policy-name",
  "format": "string"
}

The following parameters may be included in the body of the request. Any that are not included as criteria in the request are set to null. Some parameters are not accepted based on the supplied format.

See Cleanup Policies for details on which fields should be provided for a given format.

  • notes - any details on the specific cleanup policy.

  • criteriaLastBlobUpdated - the age of the component in days.

  • criteriaLastDownloaded - the last time the component had been downloaded in days.

  • criteriaReleaseType - When needed, this is either PRELEASE or RELEASE.

  • criteriaAssetRegex - a regex string to filter for specific asset paths.

  • retain - number of versions to keep. Only available for Docker and Maven release repositories on PostgreSQL deployments.

  • name - the name of the policy needs to be unique and cannot be edited once set. Only letters, digits, underscores(_), hyphens(-), and dots(.) are allowed and may not start with underscore or dot.

  • format - the target format for the cleanup policy. Some formats have various capabilities and requirements. The star "*" is for "All Formats".

    ["*", "apt", "bower", "cocoapods", "conan", "conda", "docker", "gitlfs", "go", "helm", "maven2", "npm", "nuget", "p2", "pypi", "r", "raw", "rubygems", "yum"]

Example Request

curl -u admin:admin123 -H 'accept:application/json' -H 'Content-Type: application/json' -d '{"name":"test-cleanup","format":"maven2", "criteriaLastDownloaded":10}' -X POST http://localhost:8081/service/rest/v1/cleanup-policies

Retain Select Versions Cleanup Policy

Only available for Docker and Maven release repositories on PostgreSQL deployments. To use the retain parameter, you must also include at least one of the other criteria as well.

Example Body for Retain Select Maven Component Versions

{
  "criteriaLastDownloaded": 60,
  "criteriaReleaseType": "RELEASES",
  "retain": 3,
  "name": "maven-cleanup-policy",
  "format": "maven2"
}

The sort order in which the latest versions to retained is determined by the supported formats.

  • Docker format - versions are sorted by component age. Older versions than the last retained versions are cleaned up.

  • Maven format - sorted by component version (normalized). Version numbers outside of the last retained versions are cleaned up.

You may see the below message when attempting to use the retain property without PostgreSQL. This is due to the PostgreSQL requirement for using this functionality.

"The current data source is not supported by the exclusion criteria"

See the topic Cleanup Policies for Retain Select Versions for details.

Modify existing cleanup policies. The user requires the following permissions: (nexus:settings.edit). Use the policy name as a path parameter and inside the body object. The request returns a 204 on a successful update or 404 when the policy name is not found.

PUT /service/rest/v1/cleanup-policies/{name}

See the Create Cleanup Policy for body parameters. The policy name may not be modified.

Remove Cleanup Policy from Nexus Repository. The user requires the following permissions: (nexus:settings.edit). Returns a 204 response when the cleanup policy is successfully deleted, and a 404 when the policy name is not found.

DELETE /service/rest/v1/cleanup-policies/{name}

Example

curl -u admin:admin123 -X DELETE http://localhost:8081/service/rest/v1/cleanup-policies/test-cleanup