CI Pipelines for Java, Node.js, Python and .NET: Maven, Gradle, npm, pip Builds With Caching
The Shape of Every CI Pipeline
text
checkout ─► install dependencies ─► compile / build ─► unit tests ─► report results ─► package ─► archive
The commands change per language, but the pattern is the same. Always use the non-interactive, reproducible command (npm ci, not npm install; mvn -B, batch mode).
Java With Maven
groovy
pipeline {
agent { docker { image 'maven:3.9-eclipse-temurin-21'; args '-v maven-repo:/root/.m2' } }
options { timestamps(); timeout(time: 30, unit: 'MINUTES') }
stages {
stage('Build') {
steps { sh 'mvn -B -ntp clean compile' }
}
stage('Test') {
steps { sh 'mvn -B -ntp test' }
post {
always {
junit testResults: '**/target/surefire-reports/*.xml', allowEmptyResults: true
recordCoverage(tools: [[parser: 'JACOCO']])
}
}
}
stage('Package') {
steps { sh 'mvn -B -ntp -DskipTests package' }
post { success { archiveArtifacts artifacts: 'target/*.jar', fingerprint: true } }
}
}
}
-Bbatch mode (no colours or prompts),-ntpno transfer progress spammvn verifyalso runs integration tests;mvn deploypublishes to a repository- Cache
~/.m2with a volume or use a proxy repository like Nexus
Java With Gradle
groovy
pipeline {
agent { docker { image 'gradle:8-jdk21'; args '-v gradle-cache:/home/gradle/.gradle' } }
stages {
stage('Build and test') {
steps { sh './gradlew --no-daemon --build-cache clean build' }
post { always { junit '**/build/test-results/test/*.xml' } }
}
stage('Archive') {
steps { archiveArtifacts artifacts: 'build/libs/*.jar', fingerprint: true }
}
}
}
Node.js
groovy
pipeline {
agent { docker { image 'node:22-alpine' } }
environment { npm_config_cache = "${WORKSPACE}/.npm" }
stages {
stage('Install') { steps { sh 'npm ci' } }
stage('Lint') { steps { sh 'npm run lint' } }
stage('Test') {
steps { sh 'npm test -- --ci --reporters=default --reporters=jest-junit' }
post { always { junit allowEmptyResults: true, testResults: 'junit.xml' } }
}
stage('Build') { steps { sh 'npm run build' } }
stage('Archive') { steps { archiveArtifacts artifacts: 'dist/**', fingerprint: true } }
}
}
Python
groovy
pipeline {
agent { docker { image 'python:3.12-slim' } }
environment { PIP_CACHE_DIR = "${WORKSPACE}/.pip-cache" }
stages {
stage('Setup') {
steps {
sh '''
python -m venv .venv
. .venv/bin/activate
pip install -r requirements.txt -r requirements-dev.txt
'''
}
}
stage('Lint and test') {
steps {
sh '''
. .venv/bin/activate
ruff check .
pytest --junitxml=report.xml --cov=app --cov-report=xml
'''
}
post { always { junit 'report.xml' } }
}
}
}
.NET
groovy
pipeline {
agent { docker { image 'mcr.microsoft.com/dotnet/sdk:8.0'; args '-e DOTNET_CLI_HOME=/tmp -e HOME=/tmp' } }
stages {
stage('Restore') { steps { sh 'dotnet restore' } }
stage('Build') { steps { sh 'dotnet build --no-restore -c Release' } }
stage('Test') {
steps { sh 'dotnet test --no-build -c Release --logger "trx;LogFileName=results.trx"' }
post { always { mstest testResultsFile: '**/*.trx' } }
}
stage('Publish') { steps { sh 'dotnet publish -c Release -o out' ; archiveArtifacts 'out/**' } }
}
}
Skip Work When Only Docs Changed
groovy
stage('Build and test') {
when {
not {
changeset pattern: '^(docs/.*|.*\\.md)$', comparator: 'REGEXP' // run unless ONLY docs matched? see note
}
}
steps { sh 'mvn -B verify' }
}
Changesets are tricky:
changeset is true if any changed file matches. To skip builds when only documentation changed, check in a script step with git diff --name-only and decide, or use a rule such as [skip ci] in commit messages with the SCM Skip plugin.
Monorepo Tips
- Build only the services that changed:
when { changeset 'services/payments/**' }per stage - Use shallow clones and sparse checkout for huge repositories
- Run the affected services in
parallelstages - Consider build tools made for monorepos (Nx, Bazel, Gradle composite builds)
Caching Compared
| Method | Pros | Cons |
|---|---|---|
Docker volume or PVC for .m2, .npm, .cache/pip | Simple and fast | Shared state can leak between builds; concurrency issues |
| Proxy repository (Nexus, Artifactory) | Fast for all agents and teams, central control, caches Maven, npm, PyPI, Docker | One more service to run |
| Persistent agents with local caches | Fast | Not clean; needs housekeeping |
| No cache | Always clean | Slow and uses bandwidth |
Practice Tasks
- Write pipelines for two languages you use, with test reports published
- Add a cache for your dependency manager and compare build times
- Make a stage run only when files under
backend/changed - Add a lint stage that fails the build on warnings
- Use
parallelto run unit and lint stages at the same time
Conclusion
All CI pipelines follow the same shape: install, build, test, report, package, archive. Use batch and reproducible commands, publish test results in post always, run inside language-specific Docker images and speed up with caches or a proxy repository.
Quick Summary: shape; Maven/Gradle/Node/Python/.NET Jenkinsfiles; skip docs; monorepo; caching options.

