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:
Step 2: Upload the json file Use the following method and interface to upload the corresponding json file containing groovy operations
Step 3: Execute the groovy file Use the following interface to execute the groovy script uploaded in step 2:
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:
|
<<: Centos6.9 installation Mysql5.7.18 step record
>>: Implementation of code optimization for Vue2.x project performance optimization
Table of contents Preface What is data binding? T...
This article shares the specific code of js+Html ...
This article example shares the specific code of ...
This article summarizes the implementation method...
Description and Introduction Docker inspect is a ...
Table of contents Preface 1. Technical Principle ...
Create a project directory mkdir php Create the f...
Date-type single-row functions in MySQL: CURDATE(...
Table of contents 1. Add monitoring Linux host 2....
1. Linux installation (root user operation) 1. In...
Recently, I want to regularly back up important i...
What is a big deal? Transactions that run for a l...
The purpose of using HTML to mark up content is t...
<br />Table is an awkward tag in XHTML, so y...
This article shares the specific code of JS to ac...