Introduction
In the DevOps ecosystem, seamless collaboration between tools is key to achieving efficient and reliable software delivery. Jenkins, a leading CI/CD automation tool, is often used to build and test applications, producing artifacts like WAR files as outputs. However, managing these artifacts effectively—storing them securely, versioning them, and making them readily available for deployment—requires a robust repository solution.
Enter Nexus Repository Manager, a powerful tool designed to manage build artifacts with precision and scalability. By integrating Jenkins with Nexus, organizations can automate artifact storage, ensure traceability, and streamline deployment pipelines.
In this blog, we’ll explore how to integrate Jenkins with Nexus to store WAR files, using real-world examples and best practices to highlight the benefits of this setup.
What is Nexus?
Nexus is a repository manager that helps in storing, managing, and retrieving build artifacts, such as WAR, JAR, and Docker images, enabling efficient artifact lifecycle management and supporting CI/CD pipelines.
Why Use Jenkins with Nexus for Artifact Management?
Centralized Storage: Nexus acts as a central repository for all your artifacts, making it easy to manage and retrieve builds.
Version Control: It provides versioning capabilities for artifacts, ensuring traceability.
Secure and Scalable: With role-based access control, Nexus ensures that your artifacts are secure and can handle enterprise-scale storage needs.
Real-Time Scenario: Automating Artifact Management for a Banking Application
The Challenge:
Imagine you're part of a DevOps team managing a multi-tier banking application. The application requires frequent updates, and the build pipeline generates a WAR file as the deployable artifact. Without an automated system for artifact storage and retrieval, your team faces several issues:
Manual Handling: Storing the WAR file manually leads to errors and inefficiencies.
Versioning Confusion: It's difficult to track which version of the WAR file is currently deployed.
Deployment Delays: Manually locating and retrieving artifacts slows down deployments.
Security Risks: Untracked storage of artifacts increases the risk of unauthorized access or data loss.
The Solution:
By integrating Jenkins with Nexus, you can automate the process of storing and managing the WAR file. Every time Jenkins completes a build, the WAR file is automatically pushed to a hosted repository in Nexus. This repository acts as a centralized, secure storage for all your application artifacts, making it easy to track versions and retrieve the files for future deployments.
How It Works:
Jenkins Pipeline: The pipeline builds the WAR file from the source code.
Nexus Integration: Using the Nexus Artifact Uploader plugin, the pipeline uploads the WAR file to the Nexus repository.
Artifact Versioning: Nexus automatically assigns a version to the uploaded artifact, ensuring traceability.
Deployment: The CD pipeline pulls the specific WAR file version from Nexus and deploys it to the Tomcat server.
This integration eliminates manual intervention, improves traceability, and ensures secure artifact storage—allowing the banking application to be deployed efficiently and reliably.
During a production deployment, you notice that a recent release of the banking application has a bug. Nexus allows you to quickly retrieve the last stable version of the WAR file, enabling a swift rollback without disrupting services.
Step by step process to integrating the Nexus with Jenkins
STEP-1: LAUNCH INSTANCE WITH T2.MEDIUM AND 8081 PORT AND 20 GB OF EBS VOLUME
STEP-2: INSTALL JAVA17 AS THE NEXUS DEPENDENCY
yum install java-17-amazon-corretto -y
STEP-3: CREATE A FOLDER
mkdir /app
SETP-4: GO TO FOLDER
cd /app
STEP-5: DOWNLOAD THE NEUXS
wget -O nexus.tar.gz https://download.sonatype.com/nexus/3/latest-unix.tar.gz
STEP-6: UNTAR THE FILE
tar -zxvf nexus.tar.gz
STEP-7: RENAME THE FODLER
mv nexus-* nexus
STEP-8: ADD NEXUS USER
useradd nexus
STEP-9: CHANGE THE OWNERS OF THE FILES
chown -R nexus:nexus *
STEP-10: CHANGE nexus.rc file
vim /app/nexus/bin/nexus.rc
run_as_user="nexus"
STEP-11: NOW START THE NEXUS
./nexus/bin/nexus start
STEP-12: CHECK THE STATUS
./nexus/bin/nexus status
wait for 2 minutes and copy the public-ip of your nexus server and access it with 8081 port
CLICK ON SIGN-IN
IT WILL ASKS THE USER NAME & PASSWORD
USERNAME: admin
PASSWORD:
cat /app/sonatype-work/nexus3/admin.password
use this command in our server to get the password and paste it into our nexus dashboard
Click on Next
Setup new password and click on Next
Select Enable anonymous access and click on Next
Click on Finish
NOW GO TO SERVER ADMINISTRATION AND CONFIGURATION
SELECT REPOSITORIES
SELECT CREATE-REPOSITORY
SELECT MAVEN2(HOSTED)
GIVE REPOSITORY NAME AS myrepo and deployment policy as Allow redeploy and click on create repositories
now you can see our repository created in dashboard
NOW GO TO JENKINS AND INSTALL PLUGIN "nexus artifactory uploader"
Open the Jenkins job and configure the job, if you dont know how? you can refer this blog first
Go to build steps and select Nexus artifact uploader and add the nexus credentials
Now click on Add artifact
Now save the configurations and build the job. If the build gets success, then war file will gets stored on Nexus Repository.
Now open the Nexus Repository
Thats how we can integrate the nexus with Jenkins, In upcoming blogs i will show you in pipeline jobs also.
Conclusion
Integrating Jenkins with Nexus for storing WAR files not only streamlines your DevOps workflow but also adds a layer of security and efficiency to your artifact management process. By following this guide, you can ensure your builds are well-organized and readily available for deployment.
If you love stories that inspire learning, growth, and productivity, consider subscribing for more! If this article added value to your journey, your support would mean the world to me — only if it’s within your means. Let’s stay connected on LinkedIn too. Thank you for reading 💕