How to create or delete a repository in Nexus 3.2 OSS from command prompt

1,114 views
Skip to first unread message

nSarabu

unread,
Dec 6, 2017, 4:26:36 AM12/6/17
to Nexus Users
Hi All,
       New user of Nexus, started using the Nexus OSS 3.2. Now i would like to create or delete a repository outside the Nexus UI, from command line.
Any help would be appreciated.

Regards,
nSarabu

Rich Seddon

unread,
Dec 6, 2017, 10:06:14 AM12/6/17
to Nexus Users
You can write a groovy script which does these things, and execute it from the REST API interface:


Rich

nSarabu

unread,
Dec 7, 2017, 1:34:22 AM12/7/17
to Nexus Users
Thanks for the info. I am able to write a groovy as below based on the documentation and create a rawHosted repository using it:
                    {
        "name": "createRAW",
        "content": "repository.createRawHosted('private')",
        "type": "groovy"
    }

but not able to delete the repository... how do i get the list of methods that can be used in the groovy creation. When i tried running the below script to delete:
        {
  "name": "deleteRAW",
  "type": "groovy",
  "content": "repository.deleteRawHosted('private')"
}
getting this error:
   {
  "name" : "deleteRAW",
  "result" : "javax.script.ScriptException: groovy.lang.MissingMethodException:
No signature of method: org.sonatype.nexus.script.plugin.internal.provisioning.R
epositoryApiImpl.deleteRawHosted() is applicable for argument types: (java.lang.
String) values: [private]\nPossible solutions: createRawHosted(java.lang.String)
, createRawHosted(java.lang.String, java.lang.String)"
}

Regards,
Niharika.

Rui Lopes

unread,
Dec 7, 2017, 1:41:26 AM12/7/17
to nSarabu, Nexus

--
You received this message because you are subscribed to the Google Groups "Nexus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nexus-users+unsubscribe@glists.sonatype.com.
To post to this group, send email to nexus...@glists.sonatype.com.
To view this discussion on the web visit https://groups.google.com/a/glists.sonatype.com/d/msgid/nexus-users/5bfbbd86-1b0a-43ee-95bc-341c457df466%40glists.sonatype.com.

nSarabu

unread,
Dec 7, 2017, 4:46:05 AM12/7/17
to Nexus Users, niharik...@iongroup.com
 Thanks Rui,
Suggested commit helped in deleting a repository. But can we pass the repository name dynamically, instead of hard coding in groovy (for creation and deletion, how do i pass the names through url). If yes, please let me know the ways of doing it.
Also i am deploying the artifacts into Nexus using curl command. When deploy same artiact twice , i could see the increase in blob count and increase in the disk space. I don't want to duplicate the artifacts, i would like to replace existing artifact while re-deploy it. Please suggest me a way of doing it. Correct me if i am not using the Nexus in correct way.

Regards,
Niharika.

nSarabu

unread,
Dec 7, 2017, 4:56:24 AM12/7/17
to Nexus Users, niharik...@iongroup.com
Also let me know, how to disable the checkbox for "
Validate that all content uploaded to this repository is of a MIME type appropriate for the repository format" from the groovy while creating the repository.

Sarabu Niharika

unread,
Dec 13, 2017, 1:30:31 AM12/13/17
to Rich Seddon, Nexus Users

Hello Rich,

                I am able to write the groovy as you suggested. Currently I am writing  the below and saving the file as Json “createRAW.json”:

“{

  "name": "createRAW",

  "type": "groovy",

  "content": "repository.createRawHosted('private','Main')"

}”

                Executing the curl POST command to the NXRM URL as below:

curl -X POST -u admin: xxxxxx --header "Content-Type: application/json" "http://localhost:8081/service/siesta/rest/v1/script" -d @"C:\createRAW.json"

                Then I am able to execute the script with another curl command:

curl -X POST -u admin: xxxxxx --header "Content-Type: text/plain" http://localhost:8081/service/siesta/rest/v1/script/createRAW/run

                With this I am able to create Raw Hosted repository in the NXRM with the name “Private”. But now my requirement is to pass the repository name dynamically to the URL instead of hard coding the JSON file. So please let me know the way to do it.

                Also let me know if there is any other easier way of creating the repository, instead of the above process which I am following now.

                Thanks in advance.

 

Regards,

Niharika.

--
You received this message because you are subscribed to a topic in the Google Groups "Nexus Users" group.
To unsubscribe from this topic, visit https://groups.google.com/a/glists.sonatype.com/d/topic/nexus-users/fB245hjTLNg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to nexus-users...@glists.sonatype.com.


To post to this group, send email to nexus...@glists.sonatype.com.

Peter Lynch

unread,
Dec 13, 2017, 9:20:33 AM12/13/17
to Sarabu Niharika, Rich Seddon, Nexus Users
On Wed, Dec 13, 2017 at 2:30 AM, Sarabu Niharika <niharik...@iongroup.com> wrote:

Hello Rich,

                I am able to write the groovy as you suggested. Currently I am writing  the below and saving the file as Json “createRAW.json”:

“{

  "name": "createRAW",

  "type": "groovy",

  "content": "repository.createRawHosted('private','Main')"

}”

                Executing the curl POST command to the NXRM URL as below:

curl -X POST -u admin: xxxxxx --header "Content-Type: application/json" "http://localhost:8081/service/siesta/rest/v1/script" -d @"C:\createRAW.json"

                Then I am able to execute the script with another curl command:

curl -X POST -u admin: xxxxxx --header "Content-Type: text/plain" http://localhost:8081/service/siesta/rest/v1/script/createRAW/run

                With this I am able to create Raw Hosted repository in the NXRM with the name “Private”. But now my requirement is to pass the repository name dynamically to the URL instead of hard coding the JSON file. So please let me know the way to do it.


You can find this information is in our help pages:

 

                Also let me know if there is any other easier way of creating the repository, instead of the above process which I am following now.

                Thanks in advance.

 

Regards,

Niharika.

 

From: Rich Seddon [mailto:rse...@sonatype.com]
Sent: 06 December 2017 08:36 PM
To: Nexus Users <nexus...@glists.sonatype.com>
Subject: Re: How to create or delete a repository in Nexus 3.2 OSS from command prompt

 

You can write a groovy script which does these things, and execute it from the REST API interface:

 

 

Rich

On Wednesday, December 6, 2017 at 3:26:36 AM UTC-6, nSarabu wrote:

Hi All,

       New user of Nexus, started using the Nexus OSS 3.2. Now i would like to create or delete a repository outside the Nexus UI, from command line.

Any help would be appreciated.

 

Regards,

nSarabu

--
You received this message because you are subscribed to a topic in the Google Groups "Nexus Users" group.
To unsubscribe from this topic, visit https://groups.google.com/a/glists.sonatype.com/d/topic/nexus-users/fB245hjTLNg/unsubscribe.

To unsubscribe from this group and all its topics, send an email to nexus-users+unsubscribe@glists.sonatype.com.

--
You received this message because you are subscribed to the Google Groups "Nexus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nexus-users+unsubscribe@glists.sonatype.com.
To post to this group, send email to nexus...@glists.sonatype.com.

Sarabu Niharika

unread,
Dec 14, 2017, 1:45:32 AM12/14/17
to Peter Lynch, Rich Seddon, Nexus Users

I could pass the single variable using -d as in below:

                {

                                "name": "createRAW",

                                 "type": "groovy",

                                "content": "repository.createRawHosted(args)"

}

 

And in the curl to run script passing parameter -d “Test”. This is creating a repo with the name Test in the default blob store, but I wanted to create a repository with the dynamic values of all the below mentioned parameters in the signature of the method.

 

                repository.createMavenHosted("private", BlobStoreManager.DEFAULT_BLOBSTORE_NAME, VersionPolicy.RELEASE, WritePolicy.ALLOW_ONCE, LayoutPolicy.STRICT)

                Help me figuring out the Json file needs to be create with all dynamic values from the URL parameters. Give me Sample file and command format if possible for the above scenario. Also with all variable values that can be passed to each argument in the createRawHosted() method.

                (Example: WritePolicy.ALLOW_ONCE, what is the value that I need to pass for Allow-redeploy in the UI)

 

Regards,

Niharika.

To unsubscribe from this group and all its topics, send an email to nexus-users...@glists.sonatype.com.

--
You received this message because you are subscribed to the Google Groups "Nexus Users" group.

To unsubscribe from this group and stop receiving emails from it, send an email to nexus-users...@glists.sonatype.com.

Sarabu Niharika

unread,
Dec 18, 2017, 1:35:00 AM12/18/17
to ply...@sonatype.com, rse...@sonatype.com, nexus...@glists.sonatype.com
Reply all
Reply to author
Forward
0 new messages