I’ve recently received a few questions asking how the deployment of Nexus can be automated as much as is possible by using configuration management tools such as Chef, Puppet, Saltstack, Docker, etc. This is common in a scenario where you may want to set up multiple Nexuses with defined repository structures and pre-installed license keys.
In this and a following post, I’ll point you to resources that will help you do exactly that. The Sonatype engineering team has produced some awesome material on these topics over the years and this is my attempt to collate them into a coherent list. Cheers to my colleagues for providing a hailstorm of links and updated content for this project.
Using the REST API in Nexus 2.x
This first installment focuses on exploring how to automate Nexus management with the built-in REST API. In the follow-up, Nexus Deployment: Cookbooks, Modules and Playbooks, we’ll focus on how to provision and configure a Nexus server itself with the help of configuration management tools.
How do I create a repository with the REST API?
Send a POST Request to this API endpoint:
with this payload and customize as needed:
<?xml version=”1.0″ encoding=”UTF-8″?>
Issuing a GET request will return all existing repositories and can serve as a good primer on what information to provide the API. This API is authenticated and therefore will only result in a new directory if you have sufficient privileges.
How Do I retrieve artifacts from Nexus via the REST API?
There’s a great writeup on TheNEXUS by Maarten Smeets about retrieving artifacts from the API, Retrieve Artifacts from Nexus Using the REST API or Apache Ivy. This can be used to automate a number of different things, including deployment and configuration management.
Where can I find the documentation for the REST API?
Generally speaking, Nexus 2.x is designed as a system that is extended via plugins. This means there is a core Nexus service that is extended via plugins. You can see the API documentation of your Nexus instance and all it’s different features by navigating to:
Administration -> Plugins
Find the Plugin that corresponds with the functionality you want to work with and click on it. In the bottom of the screen a section with the title ‘Documentation’ will lead you to the subsequent API doc page.
How do I learn more about the REST API?
Learn the Nexus REST API: Automating Sonatype Nexus by Peter Lynch discusses the APIs of both Nexus 2 and 3. It’s a great read to understand how different functions work. You can also look at Tim O’Brien’s Learning the Nexus REST API: Read the Docs or Fire Up a Browser.
Latest posts by Ilkka Turunen (see all)
- The Latest Victim of Deserialization-Gate - November 23, 2015
- Nexus and SSL - November 4, 2015
- 3 Things Developers Can Learn from the Scandal at VW - October 28, 2015
- Automating Nexus Deployment: Cookbooks, Modules and Playbooks - August 18, 2015
- Using the REST API in Nexus 2.x - August 13, 2015