Create Maven Proxy-Repository by Script with username/password

369 views
Skip to first unread message

Dan Steffen

unread,
Jul 16, 2017, 2:04:23 AM7/16/17
to Nexus Users
Hello,

at the moment I try to automate the creation of maven-proxy repositories by the nexus3-API so I wrote this little Script:

import groovy.json.JsonSlurper; def repo=new JsonSlurper().parseText(args);
repository
.createMavenProxy(repo.name, repo.url, 'default', true, org.sonatype.nexus.repository.maven.VersionPolicy.valueOf(repo.policy), org.sonatype.nexus.repository.maven.LayoutPolicy.STRICT)

and uploaded it to the nexus3-Server and I can already give this script a json so it created for me the proxy repository. But I didn't found out till this point how can I set username and password for the new repository? Maybe there is a additional method, but I don't can figured out which, maybe someone here can help me? I would very thanksful for every helpful hint.
best regards
Dan

Nicholas Blair

unread,
Jul 17, 2017, 10:30:57 AM7/17/17
to Dan Steffen, Nexus Users
Hi Dan,
To add a local user account, you can call security.addUser, as shown here:


The rest of that gist has a few other relevant examples to what you are trying to do, like creating content selectors, privileges, and assigning roles.

--
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/b23893f6-cf3c-4165-a9f6-45d1a23da5bc%40glists.sonatype.com.
For more options, visit https://groups.google.com/a/glists.sonatype.com/d/optout.

Dan Steffen

unread,
Jul 18, 2017, 12:51:27 AM7/18/17
to Nexus Users, dan.ste...@googlemail.com
Hello Nicholas,

maybe I make a mistake in my first posting I am looking not for a option to create a new nexus user I am looking for a option to set username and password for a new maven proxy repository because some repositories are password protected and we would like to create a proxy of this ones.
best regards
Dan

Nicholas Blair

unread,
Jul 18, 2017, 7:10:23 AM7/18/17
to Dan Steffen, Nexus Users
Hi Dan - whoops, sorry I misread your question. This script uses container.lookup to access the internal RepositoryManager API directly:


Hope this helps!
Nick


Dan Steffen

unread,
Jul 25, 2017, 1:45:06 AM7/25/17
to Nexus Users, dan.ste...@googlemail.com
Hello Nick,

this helps indeed even if I was hoping for a single Methode to set Username/Password for the new Repository.
best regards
Dan

Tomasz Cichocki

unread,
Jun 21, 2018, 5:41:06 AM6/21/18
to Nexus Users, dan.ste...@googlemail.com
Hi Dan,

I use the following code:

import org.sonatype.nexus.repository.Repository;
def repo = repository.repositoryManager.browse().findResults { Repository repo -> (repo.name == 'docker-registry') ? repo : null }[0];
repo.configuration.attributes['httpclient']['authentication'] = [
'type': 'username',
'username': 'registry',
'password': '${docker_registry_password}'
];
repo.stop();
repo.update(repo.configuration);
repo.start();
Reply all
Reply to author
Forward
0 new messages