curl : safely delete artifacts from Nexus

Building and deploying a multiple module maven project is easy, but if the process failed in the middle of the modules, it could be quite troublesome to delete the artifacts that had been already uploaded to Nexus.

Though Nexus allow user to delete artifacts through the web UI, it’s tedious and error-prone to locate the artifact/version to be deleted one by one.

Fortunately, Nexus also enabled REST services, so we can compose the URLs, double check carefully and send the request to Nexus via curl.

This is the pattern of the URL that point to a certain arfifact resource in Nexus:

http://host:port/nexus/service/local/repositories/repo-id/content/group-id/artifact-id/version

The delete request can be sent with these parameters, I like to suppress the output except HTTP status code, so that it’s easier to check the result of a series of such commands run from shell script.

curl –request DELETE –write “%{http_code} %{url_effective}\\n” –user admin:admin123 –output /dev/null –silent url

PS. this problem is actually addressed by the feature of staged repository, while this feature is available in Nexus Pro edition.

Advertisements

2 responses to “curl : safely delete artifacts from Nexus

  1. Pingback: Sonatype Nexus & REST | Le blog de Guillaume Husta

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s