Cleanup Policies API

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.

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

[Get Cleanup Policies](https://help.sonatype.com/en/cleanup-policies-api.html#

get-cleanup-policies_body)

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

[Get Cleanup Policy by Policy Name](https://help.sonatype.com/en/cleanup-policies-api.html#

get-cleanup-policy-by-policy-name_body)

Required permissions (nexus:settings.read)

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

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.

[Create Cleanup Policy](https://help.sonatype.com/en/cleanup-policies-api.html#

create-cleanup-policy_body)

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.

["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 select release repositories on PostgreSQL deployments. To use the retain parameter, you must also include at least one of the other release type criteria as well.

Example Body for Retain Select Maven Component Versions

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

The sorting order to retain latest versions is format specific. See Cleanup Policies for Retain Select Versions for more details.

Note

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.

[Update Cleanup Policy](https://help.sonatype.com/en/cleanup-policies-api.html#

update-cleanup-policy_body)

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.

[Delete Cleanup Policy](https://help.sonatype.com/en/cleanup-policies-api.html#

delete-cleanup-policy_body)

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

Search results

No results found