CI/CD Pipeline with Jenkins, Maven, and Nexus for a Spring Boot Project
This guide explains how developers can commit code, update the Maven pom, use Jenkins to read the pom, upload artifacts to Nexus, and retrieve the latest package URL, illustrating a complete CI/CD workflow for a Spring Boot application.
Demo repository: https://github.com/zeyangli/springboot-helloworld.git
Overall Goal
Developers commit code and update the pom.xml information. Jenkins reads the pom file, uploads the built artifact to Nexus via the Nexus plugin, and then obtains the latest package download URL from Nexus.
Project Configuration
pom.xml File
groupId: short business name
artifactId: application name
version: version number
<groupId>demo</groupId>
<artifactId>demo-devops-service</artifactId>
<version>4.0</version>Note: The version must be changed for each update because the release Maven repository does not allow overwriting the same version.
Nexus (Create Repository)
Jenkins (CI)
Install plugin: Pipeline Utility Steps
Install plugin: Nexus Artifact Uploader
Configure scriptApproval to allow approvals
node("master"){
stage("Get Code"){
checkout scm
}
stage("Build & Unit Test"){
def mvnHome="/usr/local/apache-maven-3.6.0"
sh "${mvnHome}/bin/mvn clean install "
}
stage("Scan Code"){
println("code scan")
}
stage("Push Nexus"){
def pom = readMavenPom file: 'pom.xml'
nexusArtifactUploader(artifacts: [[artifactId: "${pom.artifactId}",
classifier: '',
file: "./target/${pom.artifactId}-${pom.version}.${pom.packaging}",
type: "${pom.packaging}"]],
credentialsId: 'nexus-admin',
groupId: "${pom.groupId}",
nexusUrl: '192.168.0.44:8081',
nexusVersion: 'nexus3',
protocol: 'http',
repository: "${pom.groupId}",
version: "${pom.version}")
}
stage("To Email "){
}
}Jenkins (CD)
Install plugin: Maven Artifact ChoiceListProvider (Nexus)
Build
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.