Set Up Jenkins on a VPS for Automated Builds — A Quick Step-by-Step Guide
Running Jenkins on a VPS gives your team full control over environment, security, and predictable costs while powering reliable CI/CD pipelines. This quick step-by-step guide walks you through choosing the right instance, installing and securing Jenkins, and configuring it for production-ready automated builds.
Setting up Jenkins on a Virtual Private Server (VPS) enables teams to run continuous integration and continuous deployment (CI/CD) pipelines reliably, with full control over environment, security, and resource allocation. This guide walks you through the technical rationale, installation steps, operational practices, and purchasing considerations so you can deploy a production-ready Jenkins instance on a VPS quickly and securely.
Why run Jenkins on a VPS?
Before diving into the setup, it’s useful to understand the core benefits and trade-offs of hosting Jenkins on a VPS versus managed CI services:
- Control and customization: A VPS gives you full root access to configure JVM options, network settings, storage, and custom plugins.
- Predictable costs: Unlike per-build billing, a VPS typically charges by resources, benefiting high-throughput teams.
- Data sovereignty: You control where artifacts, logs, and credentials live, important for compliance-sensitive projects.
- Responsibility: You must handle backups, scaling, security hardening, and uptime monitoring — tasks usually abstracted in managed services.
Technical prerequisites and design decisions
Before launching, make several key decisions that influence architecture and performance.
Choose OS and instance size
- Prefer a recent LTS Linux distribution: Ubuntu 20.04/22.04, Debian 11/12, or CentOS/RHEL (or compatible).
- Memory is critical: Jenkins runs on JVM. For small teams, start with 2–4 GB RAM; for multiple concurrent builds or Docker-heavy pipelines, choose 8–16 GB or higher.
- CPU: multi-core (2–4 cores minimum). More cores allow more executors and parallel builds.
- Storage: use fast SSD for workspace and artifact storage. Consider separate volumes for Jenkins home and build cache.
Network and security planning
- Open required ports (usually HTTP/HTTPS 80/443). Avoid exposing Jenkins directly to the Internet without a reverse proxy and HTTPS.
- Plan for SSH access to the VPS for administrative tasks and for using SSH build agents.
- Use firewall rules (ufw, firewalld, or cloud firewall) to restrict access to management ports.
Step-by-step Jenkins installation on a VPS
The following steps assume Ubuntu/Debian. Adjust package manager commands accordingly for other distributions.
1. Provision a VPS and update the OS
- Spin up a VPS with your chosen provider and access it via SSH.
- Update packages:
sudo apt update && sudo apt upgrade -y
2. Install Java (OpenJDK)
Jenkins requires Java. Use a supported OpenJDK version (LTS):
sudo apt install -y openjdk-11-jdk
Verify Java:
java -version
3. Add Jenkins repository and install
Add the official Jenkins apt repository, import the key, and install:
wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -
sudo sh -c 'echo deb https://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
sudo apt update && sudo apt install -y jenkins
4. Configure systemd and JVM options
Jenkins runs as a systemd service. Tune JVM options in /etc/default/jenkins (or /etc/sysconfig/jenkins on some distros):
- -Xmx and -Xms sizing: set
JAVA_ARGS="-Xms1g -Xmx2g"based on available RAM. - Set
JENKINS_ARGS="--httpPort=8080"or leave default if using a reverse proxy.
5. Start and enable service
sudo systemctl enable --now jenkins
Check status:
sudo systemctl status jenkins
6. Configure a reverse proxy and HTTPS
For production, place Jenkins behind Nginx or Apache and enable TLS using Let’s Encrypt. Example Nginx config skeleton:
server { listen 80; server_name jenkins.example.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; } }
Then use Certbot to obtain a certificate and enable HTTPS. Configure proxy headers to preserve client IP and protocol for correct Jenkins behavior.
7. Secure Jenkins instance
- Complete initial setup wizard and create an admin user.
- Enable HTTPS only for web access; disable anonymous access.
- Use Matrix-based security or integrate with LDAP/Active Directory for enterprise authentication.
- Configure Credentials Binding securely — store secrets in Jenkins Credentials, fine-grain permissions on access.
- Enable CSRF protection and update the Jenkins instance and plugins regularly.
8. Configure storage and backups
Jenkins data is stored in $JENKINS_HOME (default /var/lib/jenkins). Implement these practices:
- Keep periodic backups of
$JENKINS_HOME, including job configs, plugin list, and secret keys. Tools: rsync, tar, or automated backup plugins that push to S3 or external storage. - Separate workspace and build artifact directories to dedicated volumes if builds generate large artifacts.
- Use volume snapshots provided by your VPS provider for quick point-in-time recovery.
9. Install essential plugins and configure pipelines
Start with these plugin categories:
- Source control: Git plugin, GitHub Branch Source, Bitbucket Server integration.
- Pipeline: Pipeline, Pipeline Utility Steps, Declarative Pipeline.
- Credentials: Credentials Binding, SSH Credentials.
- Build environment: Docker plugin, Docker Pipeline for containerized builds.
- Monitoring & metrics: Monitoring, Prometheus metrics and exporters if you operate at scale.
Agents and scaling
Design how builds will run — on the master (not recommended for builds) or on agents. Two common agent types:
SSH agents
- Jenkins connects via SSH to remote nodes. Ensure the agent user has minimal privileges and is isolated.
- Useful for provisioning build machines on-demand using configuration management tools (Ansible, Salt).
JNLP / Kubernetes / Docker agents
- Docker agents: spin up disposable containers for each build. Requires Docker installed on agent host and Docker Pipeline plugin.
- Kubernetes plugin: dynamically create ephemeral pods for build steps — ideal when you have a Kubernetes cluster.
- JNLP agents connect back to the master and are suitable for CI clusters behind NAT.
Integrating with source control and webhooks
To trigger automated builds, configure repository webhooks (GitHub, GitLab, Bitbucket) to hit Jenkins endpoints, or use a Poll SCM strategy as fallback. For GitHub:
- Install GitHub integration plugin and configure a GitHub App or Personal Access Token credential.
- Create a webhook on the repository pointing to
https://jenkins.example.com/github-webhook/and set content type to application/json.
Performance tuning and operational best practices
- Adjust Jenkins executor count to match CPU and I/O capacity. Too many executors can cause thrashing.
- Tune JVM garbage collection with modern JVM flags and consider switching to G1GC for large heaps.
- Monitor disk I/O; builds with heavy I/O need fast SSDs or local NVMe for workspace directories.
- Use job throttling plugins to prevent resource contention for expensive build jobs.
- Keep a controlled plugin list and regularly test plugin compatibility in a staging Jenkins instance before upgrading production.
Backup and upgrade strategy
Have an upgrade and rollback plan:
- Test upgrades in a staging environment mirroring production configuration.
- Back up
$JENKINS_HOMEand plugin list before every upgrade. - Automate snapshot backups of VPS volumes and periodically verify restore process.
When to consider managed CI or alternative architectures
Running Jenkins on a VPS is powerful, but evaluate alternative approaches if:
- You want zero-maintenance CI with automatic scaling and no OS management — consider hosted CI providers.
- Your team lacks capacity for system administration, security patching, and backup operations.
- You need extreme horizontal scaling with ephemeral build runners (consider Jenkins on Kubernetes or managed Kubernetes solutions).
Choosing the right VPS for Jenkins
When selecting a VPS for Jenkins, prioritize the following:
- Memory and CPU: Jenkins master needs adequate RAM for plugins and UI operations; build agents need CPU cores for compiling and testing.
- Storage performance: SSD-backed storage reduces build times significantly, especially for artifact-heavy pipelines.
- Network throughput: For frequent artifact uploads/downloads or heavy Git operations, choose higher network bandwidth.
- Backups and snapshots: Ensure the provider supports volume snapshots or managed backups to simplify recovery.
- Geographic location: Choose a VPS region close to your team or artifact repositories to minimize latency; for US-based teams, consider a USA VPS.
For teams deploying into the United States, a reliable option is offered at USA VPS, which provides SSD storage, snapshot capabilities, and flexible CPU/memory configurations suitable for Jenkins masters and agents.
Summary
Deploying Jenkins on a VPS provides maximum control for teams that need tailor-made CI/CD environments. Key steps include choosing the right VPS sizing (memory, CPU, SSD), installing and securing Jenkins behind a reverse proxy with HTTPS, configuring agents for scalable builds, integrating source control webhooks, and implementing robust backup and upgrade workflows. With proper JVM and executor tuning, secure credential management, and a sound backup strategy, a VPS-hosted Jenkins can be a cost-effective, high-performance CI solution.
If you’re ready to provision a VPS optimized for Jenkins — with SSD storage, snapshots, and flexible resource options — consider exploring the USA VPS offerings to find a plan that matches your team’s workload and budget.