Skip to content

Instantly share code, notes, and snippets.

@jonesbusy
Created April 7, 2021 19:14
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonesbusy/7a74db90f2eae1d0725ddba44e32b2b3 to your computer and use it in GitHub Desktop.
Save jonesbusy/7a74db90f2eae1d0725ddba44e32b2b3 to your computer and use it in GitHub Desktop.
nexus_cleanup_policies.groovy
import org.sonatype.nexus.cleanup.storage.CleanupPolicyStorage
import org.sonatype.nexus.cleanup.storage.CleanupPolicyComponent
def isCleanupPolicyExists(String name) {
def cleanupPolicyStorage = container.lookup(CleanupPolicyStorage.class.getName())
return cleanupPolicyStorage.exists(name)
}
def deleteCleanupPolicy(String name) {
def cleanupPolicyStorage = container.lookup(CleanupPolicyStorage.class.getName())
def cleanupPolicyComponent = container.lookup(CleanupPolicyComponent.class.getName())
if (cleanupPolicyStorage.exists(name)) {
cleanupPolicyStorage.remove(cleanupPolicyStorage.get(name))
return true
}
return false
}
def createPolicy(String policyName, String description, String format, String lastDownloaded,
String lastBlobUpdated, String regex = null, Boolean isPrerelease = false) {
def policyStorage = container.lookup(CleanupPolicyStorage.class.getName())
def cleanupPolicy = policyStorage.newCleanupPolicy()
cleanupPolicy.setName(policyName)
cleanupPolicy.setNotes(description)
cleanupPolicy.setMode('delete')
cleanupPolicy.setFormat(format)
def criteria = [:]
if (lastDownloaded) {
criteria['lastDownloaded'] = lastDownloaded
}
if (lastBlobUpdated) {
criteria['lastBlobUpdated'] = lastBlobUpdated
}
if (regex) {
criteria['regex'] = regex
}
if (isPrerelease) {
criteria['isPrerelease'] = 'true'
}
cleanupPolicy.setCriteria(criteria)
policyStorage.add(cleanupPolicy)
}
def updatePolicy(String policyName, String description, String format, String lastDownloaded,
String lastBlobUpdated, String regex = null, Boolean isPrerelease = false) {
def policyStorage = container.lookup(CleanupPolicyStorage.class.getName())
def cleanupPolicy = policyStorage.get(policyName)
cleanupPolicy.setName(policyName)
cleanupPolicy.setNotes(description)
cleanupPolicy.setMode('delete')
cleanupPolicy.setFormat(format)
def criteria = [:]
if (lastDownloaded) {
criteria['lastDownloaded'] = lastDownloaded
}
if (lastBlobUpdated) {
criteria['lastBlobUpdated'] = lastBlobUpdated
}
if (regex) {
criteria['regex'] = regex
}
if (isPrerelease) {
criteria['isPrerelease'] = 'true'
}
cleanupPolicy.setCriteria(criteria)
policyStorage.update(cleanupPolicy)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment