Nexus 3: how to get the last shot?

As we all know, Nexus 3 does not yet have a REST API, which is very strange for me. I can upload artifacts manually using wget or curl. But since I use Maven 3, all snapshot artifacts are called using timestamps, such as:

myartifact-1.0-20161215.141522-4.tar.gz

So I want to know how can I get the latest snapshots from a repo? I want to automate the process of loading artifacts, but as the names changed, I did not find a way to achieve this.

Thank.

+4
source share
3 answers

You can create a script in Groovy and upload it to Nexus to do what you want.

script, , .

version.json:

{
  "name": "version",
  "type": "groovy",
  "content": "import org.sonatype.nexus.repository.storage.Query;
    import org.sonatype.nexus.repository.storage.StorageFacet;
    import groovy.json.JsonOutput;

    def groupId = args.split(',')[0];
    def repositoryId = args.split(',')[1];

    def repo = repository.repositoryManager.get(repositoryId);
    StorageFacet storageFacet = repo.facet(StorageFacet);
    def tx = storageFacet.txSupplier().get();

   tx.begin();
   def components = tx.findComponents(Query.builder().where('group = ').param(groupId).build(), [repo]);
   def found = components.collect {
   def baseVersion = it.attributes().child('maven2').get('baseVersion');
   \"${baseVersion}\"
   };
   found = found.unique();
   tx.commit();
   def result = JsonOutput.toJson(found);

   return result;"
}

tx.findComponents(), Component. attributes(). baseVersion Maven, ( -SNAPSHOT).

script, :

curl -v -X POST -u <NEXUS_ADMIN>:<NEXUS_PWD> --header "Content-Type:application/json" http://<SERVER_NEXUS>/nexus/service/siesta/rest/v1/script -d @version.json

:

curl -v -X POST -u <NEXUS_ADMIN>:<NEXUS_PWD> --header "Content-Type: text/plain" "http://<SERVER_NEXUS>/nexus/service/siesta/rest/v1/script/version/run" -d "com.my.groupid,snapshots"

, :

{
  "name" : "version",
  "result" : "[\"1.5.2-SNAPSHOT\",\"1.5.3-SNAPSHOT\",\"1.6.1-SNAPSHOT\",\"1.5.0-SNAPSHOT\"]"
}

, !

+5

. , , REST API, .

, , Nexus 2. Groovy , Nexus Repository Manager 3 API , , ( , ). : https://books.sonatype.com/nexus-book/reference3/scripting.html

+3

: Nexus 3 Rest api, ,

found = found.unique().sort(); 

:

-d'<reponame>,<groupid>,<artifactid>,<version>-SNAPSHOT,latest'

YMMV, . wget .

0
source

Source: https://habr.com/ru/post/1663851/


All Articles