✅ 1. What is Jenkins?
Jenkins is an open-source automation server written in Java. It helps automate the parts of software
development related to building, testing, and deploying, facilitating Continuous Integration and
Continuous Delivery (CI/CD).
🔑 Features:
Free and open-source
Plugin-based (1000+ plugins)
Supports Git, Maven, Gradle, Docker, etc.
Web UI for job management
Scriptable using Groovy
🔽 2. Download & Install Jenkins
💻 Pre-requisites:
Java JDK (11+ preferred)
Git (optional but recommended)
🪟 On Windows:
1. Install Java: [Link]
2. Download Jenkins WAR: [Link]
3. Open CMD and run:
bash
CopyEdit
java -jar [Link]
4. Access Jenkins UI: [Link]
5. Enter the initial admin password from:
makefile
CopyEdit
C:\Users\<UserName>\.jenkins\secrets\initialAdminPassword
6. Install recommended plugins and set up user credentials.
🧱 3. Create Item: Freestyle Project
Steps:
1. Dashboard → Click “New Item”
2. Enter a name (e.g., MyFirstJob)
3. Select Freestyle project
4. Configure:
o Source Code Management (Git, SVN)
o Build Triggers (e.g., GitHub webhook, Poll SCM)
o Build Steps (e.g., mvn test, shell scripts)
o Post-build Actions (email, archive artifacts)
5. Save and click “Build Now”
🔧 4. Create Pipeline View
Steps:
1. Go to Dashboard → Click “+ New View”
2. Select Pipeline view
3. Enter the name
4. Select jobs to include
5. Customize columns, sorting
6. Save
📦 5. Post-build Actions
Used to define what happens after build completion.
Examples:
Archive artifacts (e.g., JAR, WAR)
Email notifications
Deploy to a server
Trigger downstream jobs
Publish JUnit test results
☕ 6. Configure Maven and Java in Jenkins
A. Configure Java:
1. Go to Manage Jenkins → Global Tool Configuration
2. Under JDK:
o Add name (JDK11)
o Uncheck automatic install
o Provide local Java path (e.g., C:\Program Files\Java\jdk-11.0.18)
B. Configure Maven:
1. Install Maven on your machine
2. Go to Manage Jenkins → Global Tool Configuration
3. Under Maven:
o Add name (Maven3)
o Uncheck automatic install
o Provide path to Maven home (e.g., C:\apache-maven-3.8.6)
🕒 7. Cron Schedule (Build Triggers)
Jenkins supports cron-like syntax to schedule builds.
Syntax:
sql
CopyEdit
MIN HOUR DOM MON DOW
Examples:
H/5 * * * * → Every 5 minutes
@daily → Once a day
15 14 * * 1-5 → 2:15 PM Monday to Friday
@midnight → At 00:00
Use H (hash) to avoid job clustering.
🔁 8. Webhook (GitHub + Jenkins + ngrok)
What is a Webhook?
Webhook is a listener that gets triggered automatically when an event occurs (e.g., code pushed to
GitHub).
🛠 Steps to Connect GitHub → Jenkins (Using ngrok):
Step 1: Start Jenkins (locally)
bash
java -jar [Link] –httpPort=8080
Step 2: install ngrok using choco
Choco install ngrok
and set accesstoken,
ngrok config add-authtoken 325BkA5B7uFe5VMrbAzT7YovlpF_5ishm85ebHTo8oFucUCPm
host
ngrok http 8080
//ngrok http [Link]
Step 3: Configure GitHub Webhook
1. Go to your GitHub repository
2. Settings → Webhooks → Add webhook
3. Payload URL = [Link]
4. Content type = application/json
5. Events = Just the push event
6. Click Add webhook
Step 4: Configure Jenkins Job
In Freestyle/Pipeline job:
o Go to Build Triggers
o Check GitHub hook trigger for GITScm polling
Ensure GitHub repo is linked under SCM
🛠 9. Pipeline Syntax
Jenkins supports two main pipeline formats:
✍️A. Groovy Script (Declarative Syntax)
groovy
CopyEdit
pipeline {
agent any
tools {
jdk 'JDK11'
maven 'Maven3'
stages {
stage('Clone') {
steps {
git '[Link]
stage('Build') {
steps {
sh 'mvn clean install'
stage('Test') {
steps {
sh 'mvn test'
post {
success {
echo 'Build Successful 🎉'
failure {
echo 'Build Failed ❌'
}
}
🧾 B. YAML Syntax (Using Jenkinsfile Runner or Custom Plugin)
Jenkins doesn’t natively support YAML for pipeline, but plugins or wrappers like Jenkinsfile Runner
and jenkinsci/jervis allow YAML format.
Example (with [Link] plugin):
yaml
CopyEdit
pipeline:
agent: any
stages:
- stage: Build
steps:
- sh: mvn clean install
- stage: Test
steps:
- sh: mvn test
🔺 Groovy is the native and most widely supported format for Jenkins pipelines.