How to Install Jenkins for CI/CD on a VPS

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

  1. Click New Item → Pipeline
  2. Configure the pipeline to pull from your Git repository
  3. 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/jenkins regularly, including job configurations and build history

Continue Reading

Browse more articles in Popular Self-Hosted Applications.

  • jenkins, ci/cd server, jenkins pipeline, self hosted ci
  • 0 Корисниците го најдоа ова како корисно
Дали Ви помогна овој одговор?

Понудени резултати

How to Install Nextcloud on a VPS with Docker

Nextcloud is a self-hosted file sync, sharing, and collaboration platform — a...

How to Install GitLab CE on a VPS

GitLab Community Edition is a full-featured, self-hosted DevOps platform — Git repository...

How to Install Ghost CMS on a VPS

Ghost is a modern, fast, purpose-built platform for blogging and newsletters — a lighter,...

How to Set Up a Minecraft Server on a VPS

Running your own Minecraft server gives you full control over mods, plugins, and world settings....

How to Install n8n for Workflow Automation

n8n is a self-hosted workflow automation tool — connecting apps and APIs through a visual...