In modern software development, building an application is only part of the journey — managing and storing the build artifacts is just as important. As teams adopt CI/CD practices, they need a reliable way to store, version, and distribute packages such as JAR files, Docker images, or npm modules. This is where Nexus Repository Manager comes in. In this step-by-step guide, we will explore how to publish build artifacts to Nexus, understand why artifact repositories are critical in DevOps workflows, and see how they improve reliability, security, and efficiency in a CI/CD pipeline.
-
Install a run Nexus on a cloud server: In this walk through guide we are going to create a droplet on digitalocean, create and upload your public SSH key, configure the droplet firewall
After creating the cloud server we ssh into the cloud server as a root user with ssh root@<server public ip> which connects you securely
- Since we are going to use maven2 built artifacts, we install java 17 on the cloud server with
sudo apt updateand sudo apt install openjdk-17-jre-headless, then confirm java has been succesfully installed with java -version as seen below
- Download and Install Nexus
Navigate to /opt: ensures you download and extract files in the right system directory for software
cd /opt
Download Nexus archive:
wget https://download.sonatype.com/nexus/3/nexus-unix-x86-64-3.79.0-09.tar.gz which Downloads the Nexus Repository Manager tarball from Sonatype's official URL to the current directory
List and extract:
ls -lh
tar -xvzf nexus-unix-x86-64-3.79.0-09.tar.gz
- Create a nexus user with sudo privileges (if not already present) for security best practices with sudo adduser nexus
- Change ownership of Nexus directory with
chown -R nexus:nexus nexus-3.79.0-09/which ensures the Nexus app can access and modify its installation files when running as "nexus"- Change ownership of Nexus data directory with
chown -R nexus:nexus sonatype-work/which ensures the Nexus app can access and modify its installation files when running as "nexus"
- Change ownership of Nexus data directory with
Create a hosted maven snapshots repository in the nexus UI, with the respective user having a role with the necessary privileges to publish artifacts to the repository
Once this is done then we configure our maven project to publish build artifacts to the nexus hosted repo we created above with the right credentials;
- Add the
maven-deploy-pluginconfiguration thepom.xmlfile of the java maven project
Configure Credentials in settings.xml file with vim ~/.m2/settings.xml to ensures Maven can authenticate to the Nexus repository during deploy phase and <id> must match the one specified in the POM’s distributionManagement
Now its time to build and deploy the jar file to our nexus repository by simple doing mvn package and then mvn deploy to publish the packaged jar file to nexus repository
You can then check in the nexus UI under the Browser section
Lastly we can make use of the nexus rest api to interact with repository and download artifacts from our remote server ie
Execute curl -u {user}:{password} -X GET 'http://{nexus-ip}:8081/service/rest/v1/components?repository={repo-name}&sort=version' on the DigitalOcean droplet.
Execute wget followed by the result of the previous command , followed by java -jar java-app-1.0.jar & to start the application the background













Top comments (0)