Set up Java development environments, install Jenkins CI servers, configure GitHub Webhook integrations, and script multi-stage build pipelines.
Environment
Ubuntu / Jenkins Daemon
Difficulty
Intermediate
Course Module
Chapters 4–5: CI & Jenkins
Deliverables
Jenkinsfile & Webhook Proof
1. System Architecture & Workflow
The diagram below highlights the integration flow between Java runtimes, Maven build lifecycles, and a locally running Jenkins CI controller orchestration service.
2. Part 1: Step-by-Step Action Items & Key Execution Steps
STEP 1
Install Java Runtime Development Kits, Maven, and Gradle
Prepare the compiler packages required to build Java source code archives on the Linux environment.
This command adds the Java bin folder to the execution PATH variable, enabling you to run Java commands from any directory, and reloads the shell settings.
STEP 3
Generate and Compile a Maven Application Template
Bootstrap a standard Java application project structure using the Maven archetype generator and compile it.
This command writes the official Jenkins package repository source entry into apt's configuration directory, making the packages available for installation.
$ sudo apt update && sudo apt install -y jenkins
This command updates the repository indexes to include Jenkins and installs the server application binary daemon.
This command prints the temporary administrator password generated by the installer, which is required to unlock the Jenkins dashboard at http://localhost:8080.
3. Operational Pipeline Architecture
The diagram below traces the webhook-triggered continuous integration pipeline, starting from code commits through compile tests, to jar artifact outputs.
4. Part 2: Complete Deliverable Assets & Production Templates
To automate the continuous integration process, we will write a declarative Jenkinsfile. Below is a step-by-step breakdown of how this pipeline is built, followed by the final consolidated script template.
Step-by-Step Script Construction
Step 1
Define the Pipeline Block and Agent
Setup the main container block and specify where the build commands will execute.
pipeline {
agent any
}
The pipeline block wraps the entire CI structure, while agent any allows Jenkins to schedule and run the stages on any available executor agent.
Step 2
Configure Build Environment Tools
Declare the JDK and Maven tools needed to compile Java files.
tools {
maven 'M3'
jdk 'JDK17'
}
This loads specific compiler pathways configured in the Jenkins tools directory, setting up Maven (M3) and Java (JDK17).
Step 3
Implement Clean and Compile Stages
Write build stages to clear out previous compilation assets and check the compilation of Java source files.
This defines the initial steps of the pipeline: cleaning previous build outputs and compiling the current source code using standard Maven commands.
Step 4
Implement Unit Testing Stage with Reports
Execute JUnit test suites and collect outputs for dashboard graphing.
stage('Unit Testing') {
steps {
sh 'mvn test'
}
post {
always {
junit '**/target/surefire-reports/*.xml'
}
}
}
This step runs the tests. The post action block runs always (even on failures), collecting XML test logs to graph test results on the Jenkins dashboard.
Step 5
Package and Archive Artifacts
Compile the code into an executable JAR file and copy it to the Jenkins server for archiving.
This step packages the application into a JAR file, skipping tests (since they were verified in the previous stage), and archives the output jar files if the stage completes successfully.
Combined Automated Script
Save the consolidated blocks below as a file named Jenkinsfile in the root folder of your project repository, commit it, and push it to trigger the build:
pipeline {
agent any
tools {
maven 'M3'// Must match the Maven identifier configured in Jenkins Global Tool Configuration
jdk 'JDK17'// Must match the JDK identifier configured in Jenkins Global Tool Configuration
}
stages {
stage('Clean Workspace') {
steps {
echo'Cleaning workspace directories...'
sh 'mvn clean'
}
}
stage('Compile Source') {
steps {
echo'Compiling Java source files...'
sh 'mvn compile'
}
}
stage('Unit Testing') {
steps {
echo'Running unit tests...'
sh 'mvn test'
}
post {
always {
junit '**/target/surefire-reports/*.xml'
}
}
}
stage('Package Archive') {
steps {
echo'Packaging source libraries into executable binary JAR...'
sh 'mvn package -DskipTests'
}
post {
success {
archiveArtifacts artifacts: '**/target/*.jar', fingerprint: true
}
}
}
}
}
5. Deliverables Summary
Verify that the following configurations and outputs exist inside your Jenkins workspace.
Created Files / Templates
/home/devops/hello-world/POM.xml - Maven project object model build file.