How to Automate Nexus Repository Manager

Nexus a repository manager that allows you to manage, host your binaries and artifacts. It’s an open-source project that can qualify for a free Professional license. Nexus provides various repository formats such as Apt, Docker, Conan, npm, GO see the full list here. For features and more visit Sonatype homepage.

Image for post
Image for post
Tools* nexus repository manager
* docker
* groovy scripting
#simply add line below
$ vim nexus.properties
nexus.scripts.allowCreation=true
~
~
#simply add new line below
$ vim nexus.properties
nexus.scripts.allowCreation=true
nexus.security.randompassword=false
~
~
# pulling offical image
FROM sonatype/nexus3
LABEL maintainer="mehmetalibaykara@gmail.com"#copy configuration file to in docker container
COPY nexus.properties nexus-data/etc/nexus.properties
dexter@debian:codebase$ tree
├── Dockerfile
├── nexus.properties
# Let's build the docker image
$ docker build -t automate_nexus .
Sending build context to Docker daemon 105.5kB
Step 1/2 : FROM sonatype/nexus3
---> 57a6261043b9
Step 2/2 : COPY nexus.properties nexus-data/etc/nexus.properties
---> Using cache
---> 07aeb440e707
Successfully built 07aeb440e707
Successfully tagged automate_nexus:latest
#Running on port 8081, container name is nexus
$ docker run --rm -p 8081:8081 --name nexus automate_nexus
Image for post
Image for post
nexus login
-> Change admin password
-> Create new users
-> Create docker repositories: Host, Proxy and Group
-> Add role such as developer, admin etc
-> Create raw repositories
.
├── configs
│ └── nexus.properties
├── Dockerfile
└── scripts
├── addRole.groovy
├── addUpdateScript.groovy
├── dockerRepositories.groovy
├── provision.sh
├── rawRepositories.groovy
└── security.groovy
#start docker container
$ docker run --rm -d -p 8081:8081 --name nexus auto
#approximately 1 minutes later nexus server is ready
# then make the provision executable and run it by
$ chmod +x scripts/provision.sh && ./provision
debian@debian:~/nexus-automation/scripts$ ./provision.sh 
Provisioning Integration API Scripts Starting
Publishing and executing on http://localhost:8081
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.codehaus.groovy.reflection.CachedClass (file:/usr/share/groovy/lib/groovy-2.4.16.jar) to method
> 
< HTTP/1.1 200 OK
< Date: Thu, 07 May 2020 11:25:31 GMT
< Server: Nexus/3.22.1-02 (OSS)
< X-Content-Type-Options: nosniff
< Content-Type: application/json
< Content-Length: 44
<
{
"name" : "docker",
"result" : "null"
* Connection #0 to host localhost left intact
}
Successfully executed docker script
Provisioning Scripts Completed
username: test.developer
password: dev456
#For other users name and passwords check security.groovy script
Image for post
Image for post
users
Image for post
Image for post
repositories
References
* https://blog.sonatype.com/2010/04/why-nexus-for-the-non-programmer/
* https://blog.sonatype.com/automated-setup-of-a-repository-manager
*https://help.sonatype.com/repomanager3/rest-and-integration-api/script-api

Computer Science And DevOps things :)

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store