Create Smart Archiving Policy API

JFrog REST APIs

Content Type
REST API
ft:sourceType
Paligo

Description: This API is called to create a new package-level smart arching policy. For information on how to create a new smart archiving policy via the UI, see Create Smart Archiving Policy.Create Smart Archiving Policy

Security: Requires a platform admin. A project admin with permission can create a policy on the project level.

Usage: POST /artifactory/api/archive/v2/packages/policies/{policyKey}

Produces: application/json

Sample Query

POST http://{host:port}/artifactory/api/archive/v2/packages/policies/key1
{
   "key": "key1",                          // required
   "description": "some test description",
   "cronExp": "0 15 10 * * ? 2024",
   "durationInMinutes": 150,
   "enabled": false,
   "skipTrashcan": false,
   "projectKey": "pipe",                   // required if project policy
   "searchCriteria": {                     // required
       "packageTypes": [                   // required
           "docker",
           "maven"
       ],
       "repos": [                          // required
           "repo1",
           "repo2"
       ],
      "excludedRepos": [
            "gradle-global"
       ],
       "includedPackages": [               // required
           "com/jfrog"
       ],
       "excludedPackages": [
           "com/jfrog/latest"
       ],
       "includeAllProjects": false,
       "includedProjects": [],
       "createdBeforeInMonths": 12,        
       "lastDownloadedBeforeInMonths": 1,  
       "keepLastNVersions": 0              
   }
}

Query Parameters:

Field

Type

Description

key

string

An ID that is used to identify the archive policy. A minimum of three characters is required and can include letters, numbers, underscore and hyphen.

This parameter is mandatory.

description

string

A description of the policy. This parameter is optional.

cronExp

integer

The cron expression determines when the policy is run. This parameter is not mandatory, however if left empty the policy will not run automatically and can only be triggered manually.

durationInMinutes

integer

This setting limits the maximum duration (in minutes) the policy can run when enabled. The maximum allowed duration is 300 minutes.

Note

The policy stops before the completion of the run if it exceeds the applied run duration. In one run, within this duration, it archives all or part of your packages depending on the size and number of items. If there are any pending packages to be archived, they are archived incrementally in the next scheduled run and the subsequent runs.

enabled

string

An archive policy must be created inactive. This parameter is optional, but if used it must be set to FALSE. If set to TRUE when calling this API, the API call will fail and an error message is received.

Note

After an archive policy is created, it can be set to active by calling Enable/Disable Smart Archiving Policy API.

skipTrashcan

string

A true value means that when this policy is executed, packages will be permanently deleted without an option to restore them immediately, false means that when the policy is executed packages will be deleted to the Trash Can. To restore, refer to Restore Archived Packages API.

Note

If you want deleted items to be transferred to the trash can, you must enable the global Trash Can setting. To learn more, refer to Trash Can Settings.Trash Can Settings

projectKey

string

This key is obtained from the Project Settings screen. This parameter is used only for project-level archive V2 policies, it is not used for global-level policies.

searchCriteria

See below

The criteria that define aspects of the policy such as package types (docker, maven), names of repositories in which the policy will run, and other relevant criteria. For more details see the table below.

Search Criteria

Field

Type

Description

packageTypes

string

The package types that are archived by the policy. For a list of the permitted package types, click here.Smart Archiving Supported Packages

You must enter at least one package type.

repos

string

Specify one or more patterns for the repository name(s) on which you want the archive policy to run. You can also specify explicit repository names. Specifying at least one pattern or explicit name is mandatory. Only packages in repositories that match the pattern or explicit name will be archived.

excludedRepos

string

Specify patterns for repository names or explicit repository names that you want excluded from the archive policy. This parameter is optional.

includedPackages

string

Specify a pattern for a package name or an explicit package name on which you want the archive policy to run. Only one pattern or explicit name can be entered. To include all packages, use "**". For example: "includedPackages": ["**"]

This parameter is mandatory.

excludedPackages

string

Specify explicit package names that you want excluded from the policy. Only explicit names (and not patterns) are accepted. This parameter is optional.

includeAllProjects

boolean

Set this value to true if you want the policy to run on all Artifactory projects. The default value is false. This parameter is optional.

Note

This parameter is relevant only on the global level, for Platform Admins.

includedProjects

string

Enter the project keys for the projects on which you want the policy to run. To include repositories that are not assigned to any project, enter the project key default.

Note

This parameter is relevant only on the global level, for Platform Admins.

createdBeforeInMonths

integer

The archive policy will archive packages based on how long ago they were created. For example, if this parameter is 2 then packages created more than 2 months ago will be archived as part of the policy.

Note

  • A policy must use one of the three settings: createdBeforeInMonths, lastDownloadedBeforeInMonths, or keepLastNVersions.

  • createdBeforeInMonths, and lastDownloadedBeforeInMonths can be used together, but they cannot be used with keepLastNVersions. Meaning, use either createdBeforeInMonths and lastDownloadedBeforeInMonths (or just one of them), or use keepLastNVersions.

lastDownloadedBeforeInMonths

integer

The archive policy will archive packages based on how long ago they were downloaded. For example, if this parameter is 5 then packages downloaded more than 5 months ago will be archived as part of the policy.

Note

JFrog recommends using lastDownloadedBeforeInMonths to ensure that packages currently in use are not archived.

keepLastNVersions

integer

Set a value for the number of latest versions to keep. The archive policy will remove all versions before the number you select here. The latest version is always excluded.

Note

  • Versions are determined by creation date.

  • Not all package types support this condition. If you include a package type in your policy that is not compatible with this condition, a validation error (400) is returned. For information on which package types support this condition, click here.Smart Archiving Supported Packages

Sample Response:

The contents of the response are identical to the query contents.

Response Error Codes

Code

Description

400

Validation errors.

401

Bad Credentials.

403

Unauthorized.

409

A policy with the specified key already exists.

500

Internal server error.