Skip to content

Instantly share code, notes, and snippets.

Avatar

Daniel Wamara dwamara

View GitHub Profile
@dwamara
dwamara / nexus3-clean-timestamped-snapshots.groovy
Last active Dec 8, 2020
Due to the requirement from Maven to not have unique versions of SNAPSHOTS, even when a policy to clean the SNAPSHOTS is specified in Nexus 3, SNAPSHOTS that are not cleaned still contain several versions of the SNAPSHOTS artefacts timestamped. This script allows to delete the timestamped SNAPSHOTS and to keep a certain specified amount of them
View nexus3-clean-timestamped-snapshots.groovy
import groovy.json.JsonSlurper
import groovy.transform.Field
import static groovy.time.TimeCategory.minus
import static javax.xml.bind.DatatypeConverter.printBase64Binary
@Field def params = [:]
@Field def nexus = [:]
@Field def artifactsToVersion = [:]
@Field def was_at_least_one_element_delete = false
View purge_nexus_v3_releases.groovy
import org.sonatype.nexus.repository.storage.StorageFacet;
import org.sonatype.nexus.repository.storage.Query;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
def fmt = DateTimeFormat.forPattern('yyyy-MM-dd HH:mm:ss');
// Get a repository
def repo = repository.repositoryManager.get('nuget-releases');
// Get a database transaction
def tx = repo.facet(StorageFacet).txSupplier().get();