CI Pipelines for Java, Node.js, Python and .NET: Maven, Gradle, npm, pip Builds With Caching

CI CD Pipelines with Jenkins 40 min min read Updated: Nov 17, 2026 Intermediate
CI Pipelines for Java, Node.js, Python and .NET: Maven, Gradle, npm, pip Builds With Caching
Intermediate Topic 1 of 3

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 } } } } }
  • -B batch mode (no colours or prompts), -ntp no transfer progress spam
  • mvn verify also runs integration tests; mvn deploy publishes to a repository
  • Cache ~/.m2 with 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 parallel stages
  • Consider build tools made for monorepos (Nx, Bazel, Gradle composite builds)

Caching Compared

MethodProsCons
Docker volume or PVC for .m2, .npm, .cache/pipSimple and fastShared state can leak between builds; concurrency issues
Proxy repository (Nexus, Artifactory)Fast for all agents and teams, central control, caches Maven, npm, PyPI, DockerOne more service to run
Persistent agents with local cachesFastNot clean; needs housekeeping
No cacheAlways cleanSlow and uses bandwidth

Practice Tasks

  1. Write pipelines for two languages you use, with test reports published
  2. Add a cache for your dependency manager and compare build times
  3. Make a stage run only when files under backend/ changed
  4. Add a lint stage that fails the build on warnings
  5. Use parallel to 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.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators