Skip to content

sonatype-nexus-community/nexus-scripting-examples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Integration API Scripting Examples

Example projects for the Integration API as documented in https://help.sonatype.com/display/NXRM3/REST+and+Integration+API

See what other interesting scripts have been created at https://community.sonatype.com

Getting Started

Look at the examples in these projects to get more familiar with how to load, run, and write your own scripts to run inside of Nexus Repository Manager.

Step 1 - simple-shell-example

simple JSON script files and shell scripts for interaction with the REST API

Step 2 - nexus-script-example

Maven project for script development with IntelliJ IDEA-supported code completion

Step 3 - complex-script

complex provisioning setup based on a shell script invoking numerous groovy scripts for upload and execution

Passing Parameters

When running the script, the body of the POST request will be passed to your groovy in the args field. You can treat this as a normal string, use Groovy’s JsonSlurper to parse it as JSON, or read in any other groovy way.

The echo.json sample shows this in action. To test it out:

  1. First, cut and paste the contents of echo.json into the body field in the Nexus API UI for adding a new script and give your script a name, and click the "execute" button to submit the POST /v1/script request to save the script in your instance of Nexus Repository Manager

  2. Next, using the name from Step 1, execute the POST /v1/script/{name}/run request with any text you choose in the body.

  3. Notice that the response for Step 2 will return the text that you passed in!

For a more interesting example, see addRole.groovy and the corresponding documentation at the bottom of https://help.sonatype.com/repomanager3/rest-and-integration-api/script-api/examples. This script allows you to create your own custom REST API that enables you automate the creation of new Roles inside of Nexus Repository Manager.

API Reference

There are 4 officially supported API interfaces:

  1. Core

  2. BlobStore

  3. Repository

  4. Security

To learn more about the methods in each interface, use code complete in your favorite IDE with the nexus-script-example project, or take a look at the Javadoc index.html

About

Sample scripts that use NXRM's scripting interface

Resources

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages