Nexus 3 API to delete repositories

800 views
Skip to first unread message

Thiago Figueiró

unread,
Jun 24, 2018, 9:33:12 PM6/24/18
to Nexus Users
OSS 3.12.1-01

Is there a way to programatically delete repositories?

Repository creation is possible by using the REST APIs script endpoint (https://help.sonatype.com/repomanager3/rest-and-integration-api/script-api#ScriptAPI-RunScript).

e.g.:
{
 
"name": "create_some-repo",
 
"content": "
    import org.sonatype.nexus.repository.storage.WritePolicy;
    repository.createPyPiHosted('some-repo', 'default', false, WritePolicy.ALLOW_ONCE);
  "
,
   
"type": "groovy"
}


The documentation for the RepositoryApi only has Create methods:
public interface RepositoryApi
extends org.sonatype.nexus.common.script.ScriptApi

The UI itself does a POST to /service/extdirect with some sort of faux-JSON-RPC payload:

'{"action":"coreui_Repository","method":"remove","data":["some-repo"],"type":"rpc","tid":18}'


I could do something like that myself but the "tid" parameter isn't returned as part of /beta/repositories. It is, however, obtainable through the same (undocumented?) /service/extdirect API. This would be dodgy at best, so I'd rather not do it this way.

Is there another spot that I haven't looked or another approach that will allow me to delete repositories?


Many thanks
Thiago.

Alexei Znamensky

unread,
Jun 25, 2018, 7:03:55 AM6/25/18
to Nexus Users
Hi Thiago,

You can use:

repository.repositoryManager.delete("some-repo-name")

But it is possible this is an internal construct and it's subject to change without notice from Sonatype. Use at your own discretion.

Cheers,
Alexei

Thiago Figueiró

unread,
Jun 25, 2018, 6:34:35 PM6/25/18
to Nexus Users
This is definitely better than the extdirect hack I considered. I'll go with it and update when something better comes-up.

Thank you!

Michael Martz

unread,
Jun 26, 2018, 9:53:09 AM6/26/18
to Thiago Figueiró, Nexus Users
FYI, I've marked this issue as public now so it can be voted on. https://issues.sonatype.org/browse/NEXUS-15091

--
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.
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/40149e92-929c-4f70-9484-7e357d9cc430%40glists.sonatype.com.
For more options, visit https://groups.google.com/a/glists.sonatype.com/d/optout.


--
Michael Martz
Software Engineer
Sonatype
Reply all
Reply to author
Forward
0 new messages