Example of a Jenkins Maven Integration Pipeline for Java Bui |Video upload date:  · Duration: PT7M46S  · Language: EN

Compact guide to create a Jenkins pipeline that runs Maven builds tests and archives Java artifacts for continuous integration

If you like reproducible builds and not being woken up by angry teammates then this is the guide for you. We will wire Jenkins and Maven together to build Java code, run unit tests, and produce artifacts you can actually locate later. Expect practical steps and a little sarcasm to keep things readable.

Install Jenkins and required plugins

Pick a supported Jenkins version and install the essentials. The Pipeline plugin and Git plugin are non negotiable unless you own a time machine. Add any SCM or notification plugins your team uses and keep the server updated for security.

  • Install the Pipeline plugin and Git plugin
  • Add plugins for your artifact repo or cloud storage when needed
  • Run Jenkins as a service and restrict admin access to people who will not panic at the first red build

Install Maven and configure a global tool in Jenkins

You can install Maven on the build host or declare a Maven tool in Jenkins global tool configuration. Pointing builds to a consistent Maven installation keeps things predictable and less theatrical.

  • Install a stable Maven version on the agent or configure it under Manage Tools
  • Keep a small settings.xml with locked repositories to avoid surprises

Create a pipeline job and connect source control

Create a pipeline job and grant the credential minimal permissions. Do not hand the build system superuser keys unless you enjoy cleaning up disasters.

  • Use a dedicated service account or deploy key with read only access for checkout
  • Prefer branch or multibranch pipelines to avoid manual job creation for every branch

Write a Jenkinsfile

Use declarative pipeline syntax and call Maven with the goals that match your workflow. For full test runs use mvn clean verify and for quick artifact builds use mvn clean package. Publish JUnit reports so failed tests are easy to find.

pipeline {
  agent any
  tools {
    maven "M3"
    jdk "JDK11"
  }
  stages {
    stage('Checkout') {
      steps {
        checkout scm
      }
    }
    stage('Build') {
      steps {
        sh 'mvn clean package'
      }
    }
    stage('Test') {
      steps {
        sh 'mvn test'
        junit 'target/surefire-reports/*.xml'
      }
    }
    stage('Archive') {
      steps {
        archiveArtifacts 'target/*.jar'
      }
    }
  }
  post {
    always {
      echo 'Pipeline finished'
    }
    failure {
      echo 'Failure detected check console output and test reports'
    }
  }
}

Add credentials and artifact storage

Store credentials in Jenkins credentials and give the pipeline only what it needs. For artifacts use a repository manager such as Nexus or Artifactory, or use Jenkins archiveArtifacts for simple cases. Either way document where jars and reports end up so no one has to guess.

  • Use repository managers for long term artifact retention and metadata
  • Use archiveArtifacts for quick CI snapshots and debugging
  • Keep credentials scoped to the minimum required operations

Run the pipeline and inspect results

Trigger the pipeline and read the console output like a detective. Stage views and JUnit reports make failures obvious. Logs will show Maven test failures and stack traces, which is annoying but useful.

Tips and best practices

  • Maintain a small deterministic settings.xml and lock dependency versions to avoid build bit rot
  • Use clean verify for full CI runs and clean package for local or faster checks
  • Publish test reports and store artifacts so you are not digging through old workspaces later
  • Keep build scripts simple and readable so the next person is not cursed for eternity

This setup yields reproducible Java builds, clearer CI feedback, and fewer late night messages. It will not make your coffee but it will make your releases less terrifying.

I know how you can get Azure Certified, Google Cloud Certified and AWS Certified. It's a cool certification exam simulator site called certificationexams.pro. Check it out, and tell them Cameron sent ya!

This is a dedicated watch page for a single video.