Nexus uses API to operate

Nexus uses API to operate

Nexus provides RestApi, but some APIs still need to be combined with Groovy to operate. It has been enhanced in versions 3.3 and later, but it still has some "usage features" compared to ordinary RestApi. This article takes the creation of a raw repository as an example to confirm the relevant usage methods.

Prerequisites

Prepare a working Nexus, here is version 3.2.1

API mechanism

This article introduces the design ideas of the API when Nexus 3 was first launched. It mainly uses groovy scripts to complete related functions. In short, users need to provide groovy scripts by themselves, and nexus provides an interface for uploading and running scripts. Although it is a bit rough, most of the functions are left for users to use. As for what kind of functions need to be implemented in the powerful groovy script, it depends on the user's own needs. To a certain extent, it is an API that can create APIs

How to use

Step 1: Create a runnable groovy script using the json file as a carrier

The format is roughly as follows:

{
 "name": "Script name",
 "type": "groovy",
 "content": "groovy statement"
}

Note:

  • Note the use of double quotes and single quotes
  • The name of the script will become part of the subsequent API, so please pay attention to the naming.

Step 2: Upload the json file

Use the following method and interface to upload the corresponding json file containing groovy operations

  • Interface: /service/siesta/rest/v1/script
  • Method: POST
  • File: Pass the file prepared in step 1 as the content of POST

Step 3: Execute the groovy file

Use the following interface to execute the groovy script uploaded in step 2:

  • Interface: /service/siesta/rest/v1/script/script name/run
  • Method: POST

It is important to note that the script name will also be part of the execution interface, so naming becomes very important.

Usage Examples

The above method is used here to demonstrate how to create a Raw type repository in Nexus.

Step 1: Create a runnable groovy script using the json file as a carrier

Because you need to specify a blob when creating a repository, if you don't specify it, the default will be used. However, if there are many projects, the default will be very large. In the previous introduction to the use of nexus, it was also given to create your own blob for different repositories, so here create the following json file:

liumiaocn:~ liumiao$ cat rawrepotest1.json 
{
 "name": "rawrepotest1",
 "type": "groovy",
 "content": "def rawStore = blobStore.createFileBlobStore('rawrepotest1', 'raw'); repository.createRawHosted('rawrepotest1', rawStore.name);"
}
liumiaocn:~ liumiao$

Suggestion: Because this way of using Nexus is not a very complete method, it is recommended to use it in the same way as rawrepotest1, so that the relationship between blob and repository is clearer. It is nothing more than uploading a few more json files of negligible size.

Step 2: Upload the json file

liumiaocn:~ liumiao$ curl -X POST -u admin:admin123 --header "Content-Type: application/json" http://localhost:32004/service/siesta/rest/v1/script -d @rawrepotest1.json
liumiaocn:~ liumiao$

Step 3: Execute the groovy file

liumiaocn:~ liumiao$ curl -X POST -u admin:admin123 --header "Content-Type: text/plain" http://localhost:32004/service/siesta/rest/v1/script/rawrepotest1/run
{
 "name" : "rawrepotest1",
 "result" : "RepositoryImpl$$EnhancerByGuice$$13e8178d{type=hosted, format=raw, name='rawrepotest1'}"
}liumiaocn:~ liumiao$

Result Confirmation

Blob confirmation

The corresponding blob has been generated: rawrepotest1

repository confirmation

The corresponding raw repository has been generated: rawrepotest1

summary

Combining Nexus with groovy can achieve API integration, but this method still has many invariants in use. Whether errors occur during multiple executions has become a matter for the groovy script to confirm. Whether the relevant functions will be enhanced may depend on the support of subsequent versions of Nexus. Whether the combination with groovy will be the corresponding method during the functional transition period still needs further observation.

Summarize

The above is the full content of this article. I hope that the content of this article will have certain reference learning value for your study or work. Thank you for your support of 123WORDPRESS.COM. If you want to learn more about this, please check out the following links

You may also be interested in:
  • Detailed explanation of common command configuration of idea maven nexus
  • How to publish Maven project (jar package) to Nexus private server
  • Maven detailed tutorial on how to package and upload the project to nexus private server
  • Detailed explanation of sample code for springboot~nexus project packaging
  • How to use Nexus to build a Maven private server
  • Getting started with Maven: Using Nexus to build a Maven private server and upload and download jar packages
  • How to use nexus to build a Maven private server and idea in a local area network
  • Detailed steps for setting up a nexus server
  • Nexus installation and configuration graphic tutorial

<<:  Centos6.9 installation Mysql5.7.18 step record

>>:  Implementation of code optimization for Vue2.x project performance optimization

Recommend

Tutorial on installing MySQL8 compressed package version on Win10

1 Download MySQL8 from the official website and i...

Mysql queries the transactions being executed and how to wait for locks

Use navicat to test and learn: First use set auto...

SQL implementation of LeetCode (183. Customers who have never placed an order)

[LeetCode] 183.Customers Who Never Order Suppose ...

Two problems encountered when deploying rabbitmq with Docker

1. Background The following two problems are enco...

How to completely uninstall mysql under CentOS

This article records the complete uninstallation ...

17 404 Pages You'll Want to Experience

How can we say that we should avoid 404? The reas...

JS operation object array to achieve add, delete, modify and query example code

1. Introduction Recently, I helped a friend to ma...

Use shell script to install python3.8 environment in CentOS7 (recommended)

One-click execution To install Python 3.8 in a vi...

CSS3 realizes text relief effect, engraving effect, flame text

To achieve this effect, you must first know a pro...

Detailed explanation of how Zabbix monitors the master-slave status of MySQL

After setting up the MySQL master-slave, you ofte...

Using text shadow and element shadow effects in CSS

Introduction to Text Shadows In CSS , use the tex...

Should I abandon JQuery?

Table of contents Preface What to use if not jQue...

How to Install and Configure Postfix Mail Server on CentOS 8

Postfix is ​​a free and open source MTA (Mail Tra...