Introduction to Jenkins
Jenkins is an open-source automation server used to implement Continuous Integration (CI) and Continuous Deployment (CD). It allows users to create different types of jobs to automate tasks like building, testing, and deploying applications.
Freestyle Job
A Freestyle job is the simplest Jenkins job type. It allows you to configure build steps through the Jenkins UI without writing code. It is mainly used for basic automation tasks.
Steps to Create a Freestyle Job
- Open Jenkins dashboard in browser —
http://<server-ip>:8080 - Click New Item
- Enter a job name
- Select Freestyle project → Click OK
- In Source Code Management, select Git and provide repository URL
- In Build Steps, click Add build step → Execute shell
- Enter build commands like
mvn clean install - Click Save → Build Now to run the job
Pipeline Job
A Pipeline job defines the entire build and deployment process as code using a Jenkinsfile. It provides better automation, version control, and complex workflow management.
Steps to Create a Pipeline Job
- Open Jenkins dashboard → New Item
- Enter a job name → Select Pipeline → Click OK
- Scroll to Pipeline section → Choose Pipeline script from SCM
- Select SCM as Git → Enter the GitHub repository URL
- Specify the branch (e.g.,
mainormaster) - Set Script Path as
Jenkinsfile - Click Save → Build Now
Freestyle vs Pipeline Jobs
| Feature | Freestyle Job | Pipeline Job |
|---|---|---|
| Configuration | Via Jenkins UI | Defined as code in Jenkinsfile |
| Use case | Simple builds | Complex CI/CD workflows |
| Version control | Hard to version control | Easily version controlled with Git |
| Flexibility | Limited | Highly flexible and scalable |
| Recommended for | Beginners / learning | Production CI/CD pipelines |
CI/CD Pipeline for Java Web Application
Aim: Automate the build and deployment of a Java Maven web application using Jenkins and deploy it to Apache Tomcat on AWS Ubuntu.
Tools & Architecture
| Tool | Role |
|---|---|
| Java 17 | Programming language runtime |
| Apache Maven | Build and dependency management |
| Jenkins | CI/CD automation server |
| Apache Tomcat | Web server to run WAR file |
| GitHub | Source code repository |
| AWS EC2 Ubuntu | Cloud server environment |
Step-by-Step Procedure
Step 1: Install Java 17
sudo apt update
sudo apt install openjdk-17-jdk -y
java -version
Step 2: Install Maven
sudo apt install maven -y
mvn -v
Step 3: Install Jenkins
sudo apt update
sudo apt install jenkins -y
sudo systemctl enable jenkins
sudo systemctl start jenkins
sudo systemctl status jenkins
# Access Jenkins at http://<EC2-IP>:8080
Step 4: Install and Configure Tomcat
sudo apt install tomcat10 tomcat10-admin -y
# Edit Tomcat server config
sudo nano /etc/tomcat10/server.xml
# Find: <Connector port="8080" protocol="HTTP/1.1"
# Change to: <Connector port="8090" protocol="HTTP/1.1"
https://github.com/syoganandh/spring-boot-maven-example-helloworld.git
Jenkins & CI/CD — Notes PDF
Week 3 & 4 · Freestyle Jobs, Pipeline Jobs, Maven & Tomcat