Why Jenkins?
Jenkins is the leading open-source automation server used for continuous integration and continuous delivery (CI/CD). It provides hundreds of plugins to support building, deploying, and automating any project.
System Requirements
| Component | Requirement |
|---|---|
| VPS Plan | Minimum 2GB RAM (4GB+ recommended for production) |
| Operating System | Ubuntu 22.04/24.04 LTS or Debian 12 |
| Storage | 20GB+ SSD (varies based on build artifacts) |
| Java | OpenJDK 17 or 21 LTS |
Installation
Step 1: Update System Packages
Start by updating your VPS to ensure all packages are current:
sudo apt update && sudo apt upgrade -yStep 2: Install Java
Jenkins requires Java to run. Install OpenJDK 17:
sudo apt install openjdk-17-jdk -y
# Verify installation
java -versionStep 3: Add Jenkins Repository
Add the official Jenkins repository for the latest stable release:
# Import Jenkins GPG key
sudo wget -O /usr/share/keyrings/jenkins-keyring.asc \
https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key
# Add repository
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/nullStep 4: Install Jenkins
Update the package index and install Jenkins:
sudo apt update
sudo apt install jenkins -yStep 5: Start and Enable Jenkins
Enable Jenkins to start on boot and start the service:
sudo systemctl enable jenkins
sudo systemctl start jenkins
# Check status
sudo systemctl status jenkinsFirewall Configuration
Configure UFW to allow Jenkins traffic on port 8080:
sudo ufw allow 8080/tcp
sudo ufw allow OpenSSH
sudo ufw enable
# Verify rules
sudo ufw statusInitial Setup
Access Jenkins Web Interface
Open your browser and navigate to http://YOUR_VPS_IP:8080. You will see the unlock screen.
Retrieve Initial Admin Password
Get the initial administrator password:
sudo cat /var/lib/jenkins/secrets/initialAdminPasswordCopy this password and paste it into the web interface to unlock Jenkins.
Complete Setup Wizard
- Select "Install suggested plugins" for a standard setup
- Create your admin user account with a strong password
- Configure the Jenkins URL (use your VPS IP or domain)
- Click "Start using Jenkins" to complete setup
Security Hardening
Securing your Jenkins installation is critical for production environments. Follow these best practices:
Configure Reverse Proxy with Nginx
Set up Nginx as a reverse proxy to enable HTTPS and hide Jenkins behind port 443:
sudo apt install nginx -yCreate the Nginx configuration:
upstream jenkins {
keepalive 32;
server 127.0.0.1:8080;
}
server {
listen 80;
server_name jenkins.yourdomain.com;
location / {
proxy_pass http://jenkins;
proxy_http_version 1.1;
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;
proxy_connect_timeout 150;
proxy_send_timeout 100;
proxy_read_timeout 100;
}
}Enable the site and restart Nginx:
sudo ln -s /etc/nginx/sites-available/jenkins /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginxEnable SSL with Let's Encrypt
Secure your Jenkins instance with a free SSL certificate:
sudo apt install certbot python3-certbot-nginx -y
sudo certbot --nginx -d jenkins.yourdomain.comAdditional Security Measures
- Enable CSRF Protection: Manage Jenkins → Security → Enable CSRF Protection
- Configure Authentication: Use Jenkins' built-in user database or integrate with LDAP/Active Directory
- Matrix-based Security: Enable fine-grained permissions for different user roles
- Disable CLI over Remoting: Manage Jenkins → Security → Disable CLI over Remoting
- Regular Updates: Keep Jenkins and plugins updated through the web interface
Essential Plugins
Install these recommended plugins via Manage Jenkins → Plugins → Available plugins:
| Plugin | Purpose |
|---|---|
| Git | Git repository integration |
| Pipeline | Jenkinsfile-based CI/CD pipelines |
| Blue Ocean | Modern visual pipeline editor and UI |
| Docker Pipeline | Build and push Docker images |
| Credentials Binding | Secure credential management in pipelines |
| GitHub Integration | Webhooks and PR status updates |
| Slack Notification | Build notifications to Slack channels |
Performance Optimization
JVM Memory Settings
Optimize Jenkins memory usage by editing the systemd override:
sudo systemctl edit jenkinsAdd these settings (adjust values based on your VPS RAM):
[Service]
Environment="JAVA_OPTS=-Xmx2g -Xms1g -XX:+UseG1GC"
Environment="JENKINS_OPTS=--httpPort=8080"Reload and restart Jenkins:
sudo systemctl daemon-reload
sudo systemctl restart jenkinsBuild Executor Configuration
Navigate to Manage Jenkins → System → # of executors. Set the number of executors based on your VPS CPU cores:
- • I/O-bound builds: 2× the number of CPU cores
- • CPU-intensive builds: 1× the number of CPU cores
Backup Strategy
Implement regular backups of your Jenkins configuration and jobs:
#!/bin/bash
# jenkins-backup.sh
BACKUP_DIR="/opt/backups/jenkins"
JENKINS_HOME="/var/lib/jenkins"
DATE=$(date +%Y%m%d_%H%M%S)
mkdir -p $BACKUP_DIR
# Backup configuration, jobs, and credentials
tar -czf $BACKUP_DIR/jenkins-backup-$DATE.tar.gz \
$JENKINS_HOME/config.xml \
$JENKINS_HOME/jobs \
$JENKINS_HOME/users \
$JENKINS_HOME/secrets \
$JENKINS_HOME/credentials.xml \
$JENKINS_HOME/plugins
# Keep last 7 backups
ls -t $BACKUP_DIR/jenkins-backup-*.tar.gz | tail -n +8 | xargs rm -fSchedule the backup script with cron:
sudo crontab -e
# Add this line for daily backups at 2 AM
0 2 * * * /opt/scripts/jenkins-backup.shTroubleshooting
Jenkins fails to start
Check the system logs for errors:
sudo journalctl -u jenkins -f
sudo cat /var/log/jenkins/jenkins.logOut of memory errors
Increase JVM heap size in the systemd override (see Performance Optimization section) or consider upgrading your RamNode VPS plan.
Permission denied errors
Ensure the jenkins user has correct permissions:
sudo chown -R jenkins:jenkins /var/lib/jenkinsNext Steps
- Create your first Pipeline job using a Jenkinsfile
- Configure webhook integrations with your Git repository
- Set up build agents for distributed builds
- Explore Jenkins Shared Libraries for reusable pipeline code
- Monitor Jenkins performance with the Monitoring plugin
Deployment Complete!
Your Jenkins CI/CD server is now ready. Access the web interface at your configured domain, install additional plugins, and start building your automation pipelines!
