Jenkins is a widely-used, highly extensible automation server for building CI/CD pipelines — automatically testing and deploying code whenever changes are pushed.
Prerequisites
- Ubuntu 22.04/24.04 VPS: 2 vCPU, 4 GB RAM minimum
- Java installed — see How to Install Java (OpenJDK) on Ubuntu & Debian
Step 1 — Add the Jenkins Repository
curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key | sudo tee /usr/share/keyrings/jenkins-keyring.asc > /dev/null
echo "deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] https://pkg.jenkins.io/debian-stable binary/" | sudo tee /etc/apt/sources.list.d/jenkins.list > /dev/null
Step 2 — Install Jenkins
sudo apt update
sudo apt install jenkins -y
Step 3 — Enable and Start Jenkins
sudo systemctl enable --now jenkins
Step 4 — Allow the Firewall Port
sudo ufw allow 8080/tcp
Step 5 — Retrieve the Initial Admin Password
sudo cat /var/lib/jenkins/secrets/initialAdminPassword
Step 6 — Complete Initial Setup
http://YOUR_SERVER_IP:8080
Enter the password from Step 5, install suggested plugins, and create your administrator account.
Step 7 — Add HTTPS via Nginx Reverse Proxy
server {
listen 443 ssl;
server_name jenkins.yourdomain.com;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
sudo certbot --nginx -d jenkins.yourdomain.com
Creating Your First Pipeline
- Click New Item → Pipeline
- Configure the pipeline to pull from your Git repository
- Define build/test/deploy stages in a
Jenkinsfile
Example Basic Jenkinsfile
pipeline {
agent any
stages {
stage('Build') {
steps {
sh 'npm install'
}
}
stage('Test') {
steps {
sh 'npm test'
}
}
stage('Deploy') {
steps {
sh './deploy.sh'
}
}
}
}
Installing Additional Plugins
Under Manage Jenkins → Plugins, search and install plugins for specific integrations (Docker, Slack notifications, specific language toolchains).
Setting Up Webhooks for Automatic Builds
Configure your Git hosting platform (GitHub, GitLab, Gitea) to send a webhook to Jenkins on push, triggering automatic pipeline runs — the exact webhook URL and configuration is provided in each pipeline's settings.
Backing Up Jenkins
sudo tar czf jenkins-backup.tar.gz /var/lib/jenkins
Common Errors
Jenkins slow to start — normal on first boot; check status with sudo systemctl status jenkins and give it a minute.
Pipeline can't reach a private repository — configure credentials under Manage Jenkins → Credentials for SSH keys or access tokens.
Best Practices
- Run Jenkins behind HTTPS, never expose the raw port publicly in production
- Keep Jenkins and plugins updated for security patches
- Back up
/var/lib/jenkinsregularly, including job configurations and build history
Related Articles
- How to Install Java (OpenJDK) on Ubuntu & Debian
- Nginx as a Reverse Proxy for Node.js/Docker Apps
- How to Install GitLab CE on a VPS
