nexus-scripting-examples icon indicating copy to clipboard operation
nexus-scripting-examples copied to clipboard

how to add cleanup policy?

Open sahilsk opened this issue 5 years ago • 6 comments

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

sahilsk avatar Mar 14 '19 13:03 sahilsk

Hi, Any news on this?

jonashartwig avatar Sep 24 '19 06:09 jonashartwig

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.

metas-jb avatar Oct 01 '19 09:10 metas-jb

yes, thank you. I actually wanted to post my solution as well. It looks the same :)

regards

jonashartwig avatar Oct 04 '19 12:10 jonashartwig

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.

pankajrepo avatar Dec 03 '19 14:12 pankajrepo

Use this as a starting point:

CleanupPolicyStorage cleanupPolicyStorage =  container.lookup(CleanupPolicyStorage.class.name) as CleanupPolicyStorage  
cleanupPolicyStorage.add(...)

Wonno avatar Feb 21 '20 15:02 Wonno

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);

Hokwang avatar Oct 23 '20 11:10 Hokwang