Setting Up Jenkins CI with Nexus Repository Manager for Maven Artifact Management
This guide walks through installing Jenkins and Nexus Repository Manager with Docker, configuring a Maven hosted repository, adding Nexus credentials and Maven tools in Jenkins, and creating a Jenkins pipeline that builds a Java project and publishes its artifacts to Nexus, illustrating a complete CI/CD workflow.
This tutorial demonstrates how to use Jenkins as a continuous integration server together with Nexus Repository Manager as a Maven artifact repository, enabling a full CI/CD workflow for building, storing, managing, and monitoring compiled artifacts.
Jenkins installation : Run the Jenkins Docker container with docker run -d --name jenkins-ci -p 8080:8080 jenkins/jenkins:lts , access it via http://your-ip-addr:8080 , and retrieve the initial admin password using docker exec -i jenkins-ci cat /var/jenkins_home/secrets/initialAdminPassword .
Nexus installation : Pull the Nexus image with docker pull sonatype/nexus3 and start it on port 8081 using docker run -d --name nexus_repo -p 8081:8081 sonatype/nexus3 . Verify startup by checking the logs ( docker logs nexus_repo -f ) for the message "Started Sonatype Nexus OSS 3.20.1-01" and then open http://your-ip-addr:8081 to log in (default user admin and password obtained via docker exec -i nexus_repo cat /nexus-data/admin.password ).
Creating a Maven hosted repository in Nexus : In the Nexus UI, create a new repository named maven-nexus-repo , select the Maven2 format, enable redeployment, and configure appropriate storage settings.
Jenkins configuration : Install the "Nexus Artifact Uploader" plugin, add Nexus credentials under Credentials → System → Global credentials , and configure Maven as a tool in Manage Jenkins → Global Tool Configuration .
Jenkins pipeline script (shown below) defines environment variables for Nexus connection, checks out a sample Java project, builds it with Maven, and uploads the generated artifact and POM to the Nexus repository using nexusArtifactUploader :
pipeline {
agent { label "master" }
tools { maven "Maven" }
environment {
NEXUS_VERSION = "nexus3"
NEXUS_PROTOCOL = "http"
NEXUS_URL = "your-ip-addr:8081"
NEXUS_REPOSITORY = "maven-nexus-repo"
NEXUS_CREDENTIAL_ID = "nexus-user-credentials"
}
stages {
stage("Clone code from VCS") {
steps { script { git 'https://github.com/javaee/cargotracker.git' } }
}
stage("Maven Build") {
steps { script { sh "mvn package -DskipTests=true" } }
}
stage("Publish to Nexus Repository Manager") {
steps { script {
pom = readMavenPom file: "pom.xml"
filesByGlob = findFiles(glob: "target/*.${pom.packaging}")
artifactPath = filesByGlob[0].path
if (fileExists(artifactPath)) {
nexusArtifactUploader(
nexusVersion: NEXUS_VERSION,
protocol: NEXUS_PROTOCOL,
nexusUrl: NEXUS_URL,
groupId: pom.groupId,
version: pom.version,
repository: NEXUS_REPOSITORY,
credentialsId: NEXUS_CREDENTIAL_ID,
artifacts: [
[artifactId: pom.artifactId, classifier: "", file: artifactPath, type: pom.packaging],
[artifactId: pom.artifactId, classifier: "", file: "pom.xml", type: "pom"]
]
)
} else { error "*** File: ${artifactPath}, could not be found" }
} }
}
}
}The pipeline variables are explained: NEXUS_VERSION (e.g., nexus3 ), NEXUS_PROTOCOL (use http for testing, https for production), NEXUS_URL (IP and port), NEXUS_CREDENTIAL_ID (Jenkins credential ID), and the Git project URL.
After saving the job, trigger a build; upon success, Jenkins console output shows the uploaded artifact details, and the Nexus UI displays the newly stored Maven artifact, confirming a functional CI/CD pipeline that centralizes artifact management.
Finally, the guide notes that Nexus can be extended with cloud storage back‑ends such as AWS S3 or Google Cloud Storage for greater flexibility.
DevOps Cloud Academy
Exploring industry DevOps practices and technical expertise.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.