Exercise-8
8. Practical Exercise: Set Up a Jenkins CI Pipeline for a Maven Project, Use Ansible to Deploy Artifacts Generated by Jenkins.
🔧 Part 1: Install Jenkins and Maven on Ubuntu (VirtualBox)
Step 1: Update System
Step 2: Install Java (required for Jenkins & Maven)
Step 3: Install Maven
Step 4: Install Jenkins
Add Jenkins Repository
Install Jenkins
Start and Enable Jenkins
Access Jenkins
Open browser inside Ubuntu and go to:
Unlock Jenkins
Use this password to unlock Jenkins and install Suggested Plugins.
✨ Part 2: Create a Simple "Hello World" Java Maven Project
Step 1: Create Directory and Project
Step 2: Navigate to the Project
Step 3:
Edit the App.java
Step 4: Build and Test
Output will be in:
🚀 Part 3: Set Up Jenkins CI Pipeline for the Maven Project
Step 1: Open Jenkins → Create New Job
-
Choose Freestyle project
-
Name:
hello-maven-ci
Step 2: Configure Project
-
Source Code Management: None (since local project)
-
Build:
-
Add a build step: Invoke top-level Maven targets
-
Goals:
clean install
-
POM:
path-to-your-project/pom.xml
(e.g.,workspace/hello-maven/hello-maven/pom.xml
)
-
/var/lib/jenkins/workspace/
Ex:
sudo cp -r /home/anil/Desktop/hello-maven /var/lib/jenkins/workspace/
sudo chown -R jenkins:jenkins /var/lib/jenkins/workspace/hello-maven
Step 3: Save and Build
Click Build Now – Jenkins will compile and build the JAR locally.
⚙️ Part 4: Deploy Artifact Using Ansible
Step 1: Install Ansible
Step 2: Prepare Ansible Playbook
Create a directory:
Create deploy.yml
:
Step 3: Run the Playbook
Comments
Post a Comment