Skip to content

Instantly share code, notes, and snippets.

@tszpinda
Created January 7, 2016 07:57
Show Gist options
  • Save tszpinda/ee271f3397ad2df93d5f to your computer and use it in GitHub Desktop.
Save tszpinda/ee271f3397ad2df93d5f to your computer and use it in GitHub Desktop.
Nexus remove artifacts by version
def v = 30007..30017
v.each { version ->
def xml = "http://<ip>:<port>/nexus-2.1.2/service/local/data_index?v=${version}";
def baseUrl = "http://<ip>:<port>/nexus-2.1.2/content/repositories/libs-releases-local";
def parser = new XmlSlurper();
parser.setFeature('http://apache.org/xml/features/disallow-doctype-decl', true);
def root = parser.parse(xml);
root.data.artifact.each{
def groupId = it.groupId.text()
def artifactId = it.artifactId.text()
def packaging = it.extension.text()
def classifier = it.classifier?.text()
println "${groupId} - ${artifactId} - ${version} - ${classifier}"
def deleteUrl = "${baseUrl}/${groupId.replaceAll('\\.','/')}/${artifactId}/${version}/${artifactId}-${version}.${packaging}"
if (classifier)
deleteUrl = "${baseUrl}/${groupId.replaceAll('\\.','/')}/${artifactId}/${version}/${artifactId}-${version}-${classifier}.${packaging}"
println execute("curl -X DELETE -u admin:admin123 ${deleteUrl}")
};
}
def static execute(cmd){
def proc = cmd.execute();
def outputStream = new StringBuffer();
proc.waitForProcessOutput(outputStream, System.err)
return outputStream.toString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment