Integration API with Nexus Repository 3

Nexus Repository supports new repository formats such as Docker and Bower and introduces a fresh, clean user interface among other advantages. Adopting or upgrading repository manager often means that you need to update the configuration for your build tools and our documentation covers all aspects of that. Beyond that you might want to integrate the usage with your provisioning tools to automate deployment and potentially make it repeatable in different environments. Or just provide integration points for regular usage via a command-line tool and other systems.

Managing Scripts

The REST and Integration API of Nexus Repository 3 provides you features for exactly these use cases. It exposes a REST API that allows you to perform CRUD operations on your scripts as well as execute them. The scripts themselves have access to a focused API on the server.

Writing Groovy Scripts

The scripts are typically written in Groovy and stored and run on the server. This allows for a higher performance of the script execution that is less prone to fail due to connectivity issues. You can write these scripts easily with a setup such as the nexus-script-example project. Using IntelliJ IDEA, you get full code completion while developing your scripts.

The scripts can accept parameters as well as provide return values. The integration API is basically a powerful framework to create your own custom REST API and automation system for the repository manager. It includes features to manage component-related tasks like configuring your repositories and blob stores. You can set up core configurations such as HTTP proxy or base URL and configure security aspects such as roles and users.

Demos and Example Projects

The examples include a number of simple shell script and JSON files. Check out the following video to see it all in action.

Depending on your use case, you can either create one large script that does the complete configuration of a new server or numerous smaller scripts that are chained together for an execution. You can also write parameterized scripts that you run again and again with different configuration. For example, you could create a script to set up a new user as administrator and invoke it as desired. Another script could be used to deactivate a user.

A second video we created shows the editing process in the IDE and introduces the complex-script-example to demo the automated upload and execution of a number of scripts.

This example uses a combination of shell and groovy scripts for interaction with the REST API. Of course, you are free to use your scripting language of choice for these tasks.

Summary

The REST and Integration API of Nexus Repository 3 provides a huge range of possibilities for automation. The demo videos and example projects make it easy for everyone to have a look and get started.
However, if you find that your specific use case can not be easily implemented, please ensure to reach out to us by replying below so we can improve the API. Please let us know!


Acknowlegements

Original post by Manfred Moser: http://www.sonatype.org/nexus/2016/06/08/integrating-nexus-reposito-3/

For more examples, see Advanced Use Cases for the Nexus Repository Manager API

Hi @mworthington

I’m trying to add Rut Auth capability and enable Rut Auth realm using scripting API. But I haven’t found anything useful yet. The documentation examples are for repositories. Is there any way to add Rut Auth capability and enable Rut Auth realm using scripting API? Or we have to add it manually from UI?

Any help would be much apprieciated.

Hi @faizan.ahmad55,
An answer is provided at Add and enable Rut Auth capability using scripting API - #3 by mworthington

How to use the RUT Auth capability to authenticate the single sign. i.e how to pass the Post params for RUT?

https://help.sonatype.com/repomanager3/system-configuration/user-authentication/authentication-via-remote-user-token