Quantcast
Channel: TheNEXUS » documentation
Viewing all articles
Browse latest Browse all 7

Using the REST API in Nexus 2.x

$
0
0

Sonatype Q&AI’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:

HTTP://NEXUSHOST:PORT/nexus/service/local/repositories

with this payload and customize as needed:

<?xml version=”1.0″ encoding=”UTF-8″?>
<repository>
 <data>
   <id>my-releases-xml</id>
   <name>MyReleasesXml</name>
   <exposed>true</exposed>
   <repoType>hosted</repoType>
   <repoPolicy>RELEASE</repoPolicy>
   <providerRole>org.sonatype.nexus.proxy.repository.Repository</providerRole>
   <provider>maven2</provider>
   <format>maven2</format>
 </data>
</repository>

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.


Viewing all articles
Browse latest Browse all 7

Trending Articles