Tag Archives: ruby

Taking Repos Offline/Online via the Nexus REST API


April 22, 2010 By Tim O'Brien

This post runs through a simple Ruby script that manipulates the offline/online status of hosted Nexus repositories. Such a script would be useful if you need to manipulate the storage of a repository while Nexus is running. Assume you have a script that needs to backup the storage directory of all of your hosted directories once a night. If you wanted to make sure that your repository isn’t altered in the middle of a backup, you would put each hosted repository out of service before the backup job ran. After the job completed, you would put all of your hosted servers back into service.

While you could do this via the Nexus UI, this wouldn’t help your automated nightly backup script. For this script to be easy to run, you’ll need to script Nexus via the REST interface. With the Nexus 1.6 release, we’ve released full documentation of the Nexus REST services available in every Nexus installation (REST doc). Continue reading for an example of how to interact with, authenticate, and manipulate a Nexus instance via the REST APIs. Continue reading

Searching with the Sonatype Nexus REST API: Ruby


November 19, 2008 By Tim O'Brien

When you search for artifacts using http://repository.sonatype.org, the browser is querying the Nexus repository using a REST API.   In this post, I’m going to show you some simple Ruby scripts which you can use to search the Maven repository without loading up the Nexus web interface.  You might find these scripts more convenient and more customizable, and you should feel free to copy and modify them for your own use.

The following scripts are in Ruby and they use the REXML XML processor and the Net:HTTP library.  Both of these libraries are available in the Ruby standard library.   I tested these Ruby scripts using the latest JRuby release.  If you want to try these scripts out on your own, they will run in any standard Ruby interpreter without requiring any extra RubyGems. Continue reading