Master Jenkins From Beginner to Enterprise

Clear, interactive, and structured Jenkins lessons designed to take you from beginner to enterprise level.

JAR and WAR Artifacts

Learn how to securely archive, track, and manage Java archives (JAR) and Web archives (WAR) generated by your Jenkins automation build pipelines.

What are JAR and WAR Artifacts?

In the Java development ecosystem, compilation results are bundled into deployable compressed distribution files. A JAR (Java Archive) packages library classes, resources, or standalone apps with embedded servlet engines. A WAR (Web Application Archive) bundles full enterprise web applications meant to be unrolled within external application servers like Apache Tomcat or WildFly.

Once a Jenkins pipeline builds these files successfully, saving them safely is critical. Storing these binaries natively using pipeline retention rules lets you maintain clear audit logs, verify checksums, and forward verified distribution packages down to manual QA testing or automated staging deployments.

Simple Definition: The compiled, deployment-ready binary files (JARs for standalone services, WARs for external web apps) generated by a build that Jenkins preserves on its controller for tracking and distribution.

Key Concepts

Archive Archival Step

Using the declarative pipeline DSL directive archiveArtifacts to copy compiled targets out of temporary workspaces onto persistent controller memory space.

Fingerprinting

Enabling MD5 checksum hashing on stored packages to track exactly which pipeline run created a specific distribution binary across downstream jobs.

Workspace Ephemerality

Recognizing that Jenkins build node workspaces are temporary and will be cleared, making explicit artifact stashing mandatory for durability.

External Repository Handoff

Passing local archived binaries along into dedicated artifact management servers like Sonatype Nexus, JFrog Artifactory, or cloud block storage containers.

Practical Jenkins Example

This declarative pipeline demonstrates how to execute a Maven build profile that outputs a distribution file, followed by a conditional post block to capture and fingerprint the target binary package:

pipeline {
    agent any








    tools {
        jdk 'OpenJDK-17'
        maven 'Maven-3.9'
    }

    stages {
        stage('Compile & Package') {
            steps {
                echo 'Building production web package...'
                // Cleans old targets and packages code based on pom.xml definitions (producing .jar or .war)
                sh 'mvn clean package -DskipTests'
            }
        }
    }

    post {
        success {
            echo 'Build successful! Archiving generated distributions...'
            // Dynamically captures any JAR or WAR binaries residing within the target folder
            archiveArtifacts artifacts: 'target/*.jar, target/*.war', fingerprint: true, allowEmptyArchive: false
        }
        failure {
            echo 'Build failed. Skipping artifact archiving phases.'
        }
    }
}

Practice Exercise

  1. Create a new Pipeline build job in your dashboard console directory named archive-artifacts-pipeline.
  2. Paste the declarative implementation block shared above into the pipeline script field configuration area.
  3. Trigger a manual build pipeline iteration using the Build Now button.
  4. Once execution completes, return to the job's main dashboard summary screen to locate, inspect, and download your stored binaries under the Build Artifacts section.

Summary

You have completed the JAR and WAR Artifacts lesson. Mastering local artifact storage mechanics paves the way for orchestrating front-end pipelines and distributed modern architectures like Node.js and React environments.