How to Build a CI/CD Pipeline with Jenkins

Jenkins remains a widely-used, highly extensible open-source automation server — this guide covers installing Jenkins on a VPS and building a basic CI/CD pipeline.

Why Jenkins Might Fit Your Needs

Compared to hosted CI/CD (GitHub Actions, GitLab CI), Jenkins offers extensive plugin-based customization and full self-hosted control — a reasonable choice for complex, specific pipeline requirements or organizations preferring a fully self-managed CI/CD platform.

Prerequisites

  • Ubuntu 22.04/24.04 VPS: 2 vCPU, 4 GB+ RAM minimum
  • Java (Jenkins requires a JRE)

Step 1 — Install Java

sudo apt install openjdk-17-jre -y

Step 2 — Add the Jenkins Repository

curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key | sudo tee /usr/share/keyrings/jenkins-keyring.asc
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

Step 3 — Install Jenkins

sudo apt update
sudo apt install jenkins -y
sudo systemctl enable --now jenkins

Step 4 — Access the Web Interface and Unlock

sudo cat /var/lib/jenkins/secrets/initialAdminPassword
http://YOUR_SERVER_IP:8080

Step 5 — Complete Initial Setup

Install suggested plugins, create your admin user, and configure the instance URL — standard first-run wizard steps.

Step 6 — Put Jenkins Behind a Reverse Proxy with SSL

Never expose Jenkins directly on port 8080 to the public internet without SSL — see How to Set Up Nginx as a Reverse Proxy for Node.js Apps for the general reverse proxy pattern, applied here to route through Nginx with HTTPS via Let's Encrypt.

Step 7 — Create a Pipeline Job

pipeline {
    agent any
    stages {
        stage('Build') {
            steps {
                sh 'npm install'
            }
        }
        stage('Test') {
            steps {
                sh 'npm test'
            }
        }
        stage('Deploy') {
            steps {
                sh './deploy.sh'
            }
        }
    }
}

A "Jenkinsfile" defines your pipeline as code, committed alongside your application — the recommended approach over configuring pipelines purely through the web UI.

Securing Jenkins

  • Enable authentication and disable anonymous access (should already be configured during initial setup)
  • Keep Jenkins and all plugins updated regularly — a historically frequent target for vulnerabilities
  • Restrict who can create/modify pipeline jobs, since a malicious pipeline job effectively has significant server access

Managing Build Agents for Isolation

For genuinely isolated builds, configure Jenkins agents (separate from the controller) rather than running all builds directly on the Jenkins controller itself — limits the impact of a compromised or misbehaving build.

Common Errors

Jenkins consuming excessive memory — Jenkins itself plus concurrent build processes can be memory-intensive; verify your VPS has adequate RAM, and consider dedicated build agents on separate infrastructure if your build volume grows significantly.

Continue Reading

Browse more articles in DevOps & CI/CD.

  • jenkins vps setup, jenkins pipeline tutorial, jenkinsfile example, self hosted jenkins
  • 0 Bu dökümanı faydalı bulan kullanıcılar:
Bu cevap yeterince yardımcı oldu mu?

İlgili diğer dökümanlar

How to Set Up a Self-Hosted GitHub Actions Runner on a VPS

GitHub Actions' hosted runners work well for most projects, but a self-hosted runner on your own...

How to Deploy Automatically on Git Push (Webhook-Based Deployment)

Automating deployment whenever you push to a specific branch removes the manual "SSH in and pull"...

How to Set Up Blue-Green Deployment on a VPS

Blue-green deployment runs two identical production environments — only one live at a time...

How to Use Ansible for Server Configuration Management

Ansible automates server configuration through simple, human-readable YAML files — letting...

Infrastructure as Code Basics: Managing VPS Config with Terraform

Terraform lets you define infrastructure (VPS instances, networks, DNS records) as code, applied...