Jenkins Fundamentals: A Beginner's Guide

Table of contents

Introduction
Jenkins is one of the most popular open-source automation servers, widely used to implement continuous integration (CI) and continuous delivery (CD) pipelines. This guide will walk you through the fundamental concepts of Jenkins, its architecture, and how to get started.
What is Jenkins?
Jenkins is a self-contained, open-source automation server written in Java. It helps automate the parts of software development related to building, testing, and deploying code.
Key Features of Jenkins:
Open-Source: Free and customizable.
Extensible: Supports hundreds of plugins for integration.
Distributed: Scales across multiple machines.
User-Friendly: Web-based GUI for managing pipelines.
Jenkins Architecture
Jenkins follows a Master-Slave architecture:
Master Node: Manages jobs, schedules builds, and handles the user interface.
Agent/Slave Node: Executes jobs as directed by the master node.
Setting Up Jenkins
1. Install Jenkins on Linux
# Update system
sudo apt update && sudo apt upgrade -y
# Install Java (Jenkins prerequisite)
sudo apt install openjdk-11-jdk -y
# Add Jenkins repository
wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -
sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
# Install Jenkins
sudo apt update
sudo apt install jenkins -y
# Start and enable Jenkins
sudo systemctl start jenkins
sudo systemctl enable jenkins
# Access Jenkins on port 8080
http://your-server-ip:8080
2. Unlock Jenkins
After installation, retrieve the initial admin password:
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
Copy the password and paste it into the Jenkins web UI to complete the setup.
Creating Your First Jenkins Job
Go to
Dashboard
→New Item
.Enter a project name and select Freestyle Project.
Configure the following:
Source Code Management: Connect to GitHub.
Build Triggers: Select "Poll SCM" for automated builds.
Build Steps: Add shell commands for build steps.
Save and Build Now to trigger the job.
Example Shell Command:
echo "Building Project"
./build.sh
Creating a Jenkins Pipeline
Jenkins pipelines provide better flexibility and automation. Here is a simple Declarative Pipeline example.
1. Create a Pipeline Job
- Go to
Dashboard
→New Item
→ Pipeline
2. Example Jenkinsfile
pipeline {
agent any
stages {
stage('Checkout') {
steps {
git 'https://github.com/user/repo.git'
}
}
stage('Build') {
steps {
sh './build.sh'
}
}
stage('Test') {
steps {
sh './test.sh'
}
}
stage('Deploy') {
steps {
echo 'Deploying Application'
}
}
}
}
Jenkins Best Practices
Use Pipelines: Prefer Jenkins pipelines over freestyle jobs for better scalability.
Security: Implement user authentication and limit job execution permissions.
Backup: Regularly back up Jenkins home directory (
/var/lib/jenkins
).Monitor: Use plugins like Monitoring to track Jenkins' performance.
Version Control: Store Jenkinsfiles in your repository for traceability.
Common Jenkins Commands
- Restart Jenkins:
sudo systemctl restart jenkins
- View Jenkins Logs:
sudo journalctl -u jenkins
- Manage Plugins:
# Install plugin via CLI
sudo jenkins-cli.jar -s http://localhost:8080/ install-plugin PLUGIN_NAME
Conclusion
Jenkins is a powerful tool that streamlines CI/CD processes. With the fundamentals covered in this guide, you can now set up Jenkins, create jobs, and build robust pipelines. Happy automating!
Subscribe to my newsletter
Read articles from Ashutosh Verma directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
