nexus-scripting-examples
nexus-scripting-examples copied to clipboard
how to add cleanup policy?
How do we add existing cleanup policy while creating repository in this example?
https://github.com/sonatype-nexus-community/nexus-scripting-examples/blob/c0064099f6c5e5f17f92d69b9e78652c6ce3f915/nexus-script-example/src/main/groovy/maven.groovy
Hi, Any news on this?
Hi.
I found out by manually assigning a cleanup-policy to a repository, update settings and checking the log, where I found this:
org.sonatype.nexus.repository.manager.internal.RepositoryManagerImpl - Updating repository: test-repo -> Configuration{repositoryName='test-repo', ... (some uninteresting settings)}, storage={blobStoreName=default, ... (some uninteresting settings)}, cleanup={policyName=test_cleanup}}}
So I modified my groovy
script accordingly and it worked:
import groovy.json.JsonSlurper
import org.sonatype.nexus.repository.config.Configuration
parsed_args = new JsonSlurper().parseText(args)
// some basic config code here
// ...
configuration = new Configuration(
attributes: [
cleanup: [
policyName: parsed_args.cleanup_policy
],
// my other settings for storage and general policies follow here
// ...
]
)
// call function to create repository as usual
So basically you will need to create a cleanup policy and set something like cleanup.policyName(string)
Hope it helps.
yes, thank you. I actually wanted to post my solution as well. It looks the same :)
regards
Hi, can you help me how can we create a cleanup policy using groovy. I am using maven project with group id org.sonatype.nexus for accessing nexus manager.
Use this as a starting point:
CleanupPolicyStorage cleanupPolicyStorage = container.lookup(CleanupPolicyStorage.class.name) as CleanupPolicyStorage
cleanupPolicyStorage.add(...)
Hi, use this code.
import org.sonatype.nexus.cleanup.storage.CleanupPolicyStorage;
def policyStorage = container.lookup(CleanupPolicyStorage.class.getName());
def cleanupPolicy = policyStorage.newCleanupPolicy();
cleanupPolicy.setName('name');
cleanupPolicy.setNotes('');
cleanupPolicy.setMode('deletion');
cleanupPolicy.setFormat('raw');
cleanupPolicy.setCriteria(['lastBlobUpdated':'432000']);
policyStorage.add(cleanupPolicy);