---
updatedAt: 2026-04-03T15:45:07.000Z
agentTools:
  siteIndex: https://docs.jfrog.com/llms.txt
  projectIndex: https://docs.jfrog.com/administration/llms.txt
---

# Create Build Cleanup Policy

This API is called to create a new build cleanup policy. Build Cleanup Policies APIs are supported on Artifactory version 7.125 and later.

# OpenAPI definition

```json
{
  "openapi": "3.1.0",
  "info": {
    "title": "JFrog Artifactory Cleanup Policies API",
    "description": "REST API for managing cleanup policies in JFrog Artifactory. This includes cleanup policies for Packages, Release Bundles V2, and Builds.",
    "version": "1.0.0",
    "contact": {
      "name": "JFrog Support"
    }
  },
  "servers": [
    {
      "url": "https://{jfrog_url}/artifactory/api/cleanup",
      "description": "Cleanup Policies API base path"
    }
  ],
  "tags": [
    {
      "name": "Build Cleanup Policies",
      "description": "Build cleanup policy management operations"
    }
  ],
  "security": [
    {
      "BasicAuth": []
    },
    {
      "ApiKeyAuth": []
    },
    {
      "BearerAuth": []
    }
  ],
  "paths": {
    "/builds/policies/{policyKey}": {
      "post": {
        "tags": [
          "Build Cleanup Policies"
        ],
        "summary": "Create Build Cleanup Policy",
        "description": "This API is called to create a new build cleanup policy. Build Cleanup Policies APIs are supported on Artifactory version 7.125 and later.",
        "operationId": "createBuildCleanupPolicy",
        "parameters": [
          {
            "name": "policyKey",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "A unique identifier for the cleanup policy. A minimum of three characters is required, including letters, numbers, underscore and hyphen."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/BuildCleanupPolicyRequest"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/BuildCleanupPolicyResponse"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequestResponse"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "409": {
            "$ref": "#/components/responses/Conflict"
          },
          "500": {
            "$ref": "#/components/responses/InternalServerError"
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "BasicAuth": {
        "type": "http",
        "scheme": "basic"
      },
      "ApiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "X-JFrog-Art-Api"
      },
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer"
      }
    },
    "responses": {
      "BadRequestResponse": {
        "description": "Bad Request",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      },
      "Unauthorized": {
        "description": "Unauthorized",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      },
      "Forbidden": {
        "description": "Forbidden",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      },
      "Conflict": {
        "description": "Conflict",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      },
      "InternalServerError": {
        "description": "Internal Server Error",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/ErrorResponse"
            }
          }
        }
      }
    },
    "schemas": {
      "ErrorResponse": {
        "type": "object",
        "properties": {
          "errors": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "status": {
                  "type": "integer"
                },
                "message": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "BuildCleanupPolicyRequest": {
        "type": "object",
        "required": [
          "key",
          "itemType",
          "searchCriteria"
        ],
        "properties": {
          "key": {
            "type": "string",
            "description": "A unique identifier for the cleanup policy. A minimum of three characters is required, including letters, numbers, underscore and hyphen."
          },
          "description": {
            "type": "string",
            "maxLength": 256,
            "description": "A brief description of the cleanup policy."
          },
          "cronExp": {
            "type": "string",
            "description": "A cron expression specifying when the cleanup job will run. This parameter is not mandatory, however if left empty the policy will not run automatically and can only be triggered manually."
          },
          "projectKey": {
            "type": "string",
            "description": "This key is obtained from the Project Settings screen. This parameter is used only for project-level cleanup policies."
          },
          "itemType": {
            "type": "string",
            "enum": [
              "build"
            ],
            "description": "The type of items to clean up (build). This field is required."
          },
          "durationInMinutes": {
            "type": "integer",
            "description": "The maximum duration (in minutes) for policy execution, after which the policy will stop running even if not completed."
          },
          "enabled": {
            "type": "boolean",
            "description": "Indicates if the cleanup policy is active (true) or disabled (false). A cleanup policy must be created inactive."
          },
          "deleteArtifacts": {
            "type": "boolean",
            "description": "Deletes the artifacts associated with the build (true to delete)."
          },
          "skipTrashcan": {
            "type": "boolean",
            "description": "A true value means that when this policy is executed, builds will be permanently deleted. false means that when the policy is executed builds will be deleted to the Trash Can."
          },
          "searchCriteria": {
            "$ref": "#/components/schemas/BuildCleanupSearchCriteria"
          }
        }
      },
      "BuildCleanupSearchCriteria": {
        "type": "object",
        "required": [
          "includeAllProjects",
          "includedProjects",
          "includedBuilds"
        ],
        "properties": {
          "includeAllProjects": {
            "type": "boolean",
            "description": "Specifies whether to include all projects in the search (true to include)."
          },
          "includedProjects": {
            "type": "array",
            "items": {
              "type": "string"
            },
            "description": "A list of specific project keys to include in the search."
          },
          "includedBuilds": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/BuildTarget"
            },
            "description": "Builds to consider during cleanup."
          },
          "excludeBuildsWithReleaseBundles": {
            "type": "boolean",
            "description": "Specifies whether to exclude builds with release bundles (true to exclude)."
          },
          "createdBeforeInMonths": {
            "type": "integer",
            "minimum": 0,
            "description": "Specifies the time frame for filtering based on item creation date (legacy)."
          },
          "createdBeforeInDays": {
            "type": "integer",
            "minimum": 0,
            "description": "Specifies the time frame for filtering based on item creation date (e.g., 40 days)."
          }
        }
      },
      "BuildTarget": {
        "type": "object",
        "required": [
          "name",
          "projectKey"
        ],
        "properties": {
          "name": {
            "type": "string",
            "description": "The name of the build. Use wildcards at the end to match any suffix."
          },
          "projectKey": {
            "type": "string",
            "description": "The project identifier associated with the build. Leave blank for global level."
          }
        }
      },
      "BuildCleanupPolicyResponse": {
        "type": "object",
        "properties": {
          "key": {
            "type": "string",
            "description": "The ID that identifies the policy."
          },
          "description": {
            "type": "string",
            "description": "Description that was defined for the policy."
          },
          "cronExp": {
            "type": "string",
            "description": "The cron expression that determines when the policy is run."
          },
          "projectKey": {
            "type": "string",
            "description": "The project key if this is a project-level policy."
          },
          "itemType": {
            "type": "string",
            "enum": [
              "build"
            ],
            "description": "The type of items (build)."
          },
          "durationInMinutes": {
            "type": "integer",
            "description": "The maximum duration (in minutes) for policy execution."
          },
          "enabled": {
            "type": "boolean",
            "description": "Indicates if the cleanup policy is active (true) or disabled (false)."
          },
          "deleteArtifacts": {
            "type": "boolean",
            "description": "Indicates if artifacts associated with the build are deleted."
          },
          "skipTrashcan": {
            "type": "boolean",
            "description": "Indicates if builds are permanently deleted or sent to Trash Can."
          },
          "searchCriteria": {
            "$ref": "#/components/schemas/BuildCleanupSearchCriteria"
          }
        }
      }
    }
  },
  "x-readme": {
    "explorer-enabled": false
  }
}
```