1. Introduction & use cases
Jenkins is an open-source, self-hosted automation server used for CI/CD for more than a decade. Pipelines are written as code in a Jenkinsfile (Groovy-based declarative syntax) stored in your repository. Thousands of plugins connect it to Git hosts, Docker, Kubernetes, cloud providers and notification tools.
Jenkins runs on Java; the simplest way to start is the official Docker image. In production a controller schedules work and agents (other machines or containers) run the builds.
Where it is used
- CI/CD for companies that need to self-host
- Complex pipelines with many integrations and plugins
- Building on special hardware or inside private networks
- Scheduled automation jobs
2. Prerequisites
| You need | Version / notes |
|---|---|
| Docker | Easiest way to run Jenkins – see the Docker guide |
| Or Java | A Java version supported by your Jenkins LTS (Java 17 or 21) for native installs |
| Hardware | 2 GB+ RAM for the controller, more for builds |
| Git repository | With a project to build |
3. Local setup
1Run Jenkins LTS in Docker
Data is kept in the
jenkins_homevolume. Port 8080 is the web UI, 50000 is for agents.BASHdocker run -d --name jenkins --restart unless-stopped \ -p 8080:8080 -p 50000:50000 \ -v jenkins_home:/var/jenkins_home \ jenkins/jenkins:lts-jdk212Unlock Jenkins
Open http://localhost:8080 and paste the initial admin password.
BASHdocker exec jenkins cat /var/jenkins_home/secrets/initialAdminPassword3Install plugins and create the admin user
Choose Install suggested plugins (includes Pipeline and Git), then create your admin account and confirm the Jenkins URL.
4. Create & run a project
1Add a Jenkinsfile to your repository
Declarative pipeline with stages and post actions. (The controller needs Node.js for
sh 'npm …'– or run the stages in a Docker agent.)Jenkinsfilepipeline { agent any options { timestamps() } environment { NODE_ENV = 'test' } stages { stage('Install') { steps { sh 'npm ci' } } stage('Test') { steps { sh 'npm test' } } stage('Build') { steps { sh 'npm run build' } } } post { success { archiveArtifacts artifacts: 'dist/**', fingerprint: true } failure { echo 'Build failed – check the console output' } } }2Create a Pipeline job
New Item → Pipeline (or Multibranch Pipeline to build every branch) → Pipeline script from SCM → Git → repository URL and credentials → Script Path
Jenkinsfile→ Save → Build Now.3Add credentials
Manage Jenkins → Credentials → System → Global → Add Credentials: e.g. SSH Username with private key for deployments, Secret text for tokens. Use them in the Jenkinsfile:
GROOVYwithCredentials([string(credentialsId: 'api-token', variable: 'API_TOKEN')]) { sh 'curl -H "Authorization: Bearer $API_TOKEN" https://api.example.com/deploy' }4Trigger builds from GitHub
In the GitHub repository add a webhook to
https://jenkins.example.com/github-webhook/(content type JSON) and enable GitHub hook trigger for GITScm polling in the job. (Webhooks need a public URL – use polling locally.)
✅ When it works you should see output like Figure 1.
5. Development configuration
Environment variables
Use environment { } in the Jenkinsfile for normal values and the Credentials store (withCredentials, credentials()) for secrets – Jenkins masks them in console output.
environment {
APP_ENV = 'staging'
DEPLOY_HOST = '203.0.113.10'
DB_PASSWORD = credentials('db-password') // from the Credentials store
}Key dependencies
| Package / tool | Used for |
|---|---|
Pipeline plugin | Jenkinsfile support (in suggested plugins) |
Git / GitHub Branch Source | Checkout and multibranch builds |
Docker Pipeline | Run stages inside containers (agent { docker … }) |
Credentials Binding | withCredentials in pipelines |
SSH Agent | Use SSH keys for deployments |
Configuration as Code (JCasC) | Configure Jenkins from YAML |
Folder structure
my-app/
├── Jenkinsfile
├── src/
└── package.json
/var/jenkins_home/ # Jenkins data (volume)
├── jobs/
├── plugins/
└── secrets/Essential commands
| Command | What it does |
|---|---|
docker logs -f jenkins | Jenkins logs |
docker exec jenkins cat …/initialAdminPassword | First-time password |
Manage Jenkins → Plugins | Install/update plugins |
http://jenkins:8080/safeRestart | Restart after running builds finish |
Pipeline Syntax → Snippet Generator | Generate Jenkinsfile steps |
6. Production deployment
Server & hosting requirements
| Requirement | Recommendation |
|---|---|
| Server | Ubuntu VPS, 2 vCPU / 4 GB RAM for the controller |
| Agents | Separate machines/containers for builds (keep the controller light) |
| HTTPS | Nginx reverse proxy + Let’s Encrypt |
| Security | No anonymous access, matrix/role-based permissions, plugin updates |
| Backups | jenkins_home volume backed up regularly |
Deployment steps
1Prepare an Ubuntu server
Create a VPS (AWS EC2, DigitalOcean, Hostinger VPS, Linode …) with Ubuntu 24.04 LTS, at least 1 vCPU and 1–2 GB RAM. Log in with SSH, update the system and create a non-root user for the app.
BASHssh root@YOUR_SERVER_IP apt update && apt upgrade -y adduser deploy usermod -aG sudo deploy # copy your SSH key to the new user, then log in as deploy rsync --archive --chown=deploy:deploy ~/.ssh /home/deploy exit ssh deploy@YOUR_SERVER_IP2Run Jenkins in Docker on the server
Bind the UI only to localhost; Nginx will publish it with HTTPS.
BASHcurl -fsSL https://get.docker.com | sudo sh sudo docker run -d --name jenkins --restart unless-stopped \ -p 127.0.0.1:8080:8080 -p 50000:50000 \ -v jenkins_home:/var/jenkins_home \ jenkins/jenkins:lts-jdk213Install Nginx as a reverse proxy
Nginx receives requests on ports 80/443 and forwards them to your app on
127.0.0.1:8080. Replaceexample.comwith your domain. Use a subdomain such asjenkins.example.com./etc/nginx/sites-available/example.comserver { listen 80; server_name example.com www.example.com; location / { proxy_pass http://127.0.0.1:8080; 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_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; } }4Enable the site and reload Nginx
Link the config into
sites-enabled, test it and reload.nginx -tmust say syntax is ok before you reload.BASHsudo apt install -y nginx sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/ sudo nginx -t sudo systemctl reload nginx5Open only the ports you need
Allow SSH, HTTP and HTTPS through the firewall. Application ports (3000, 8000 …) stay closed to the internet – Nginx forwards traffic to them.
BASHsudo ufw allow OpenSSH sudo ufw allow 'Nginx Full' # ports 80 and 443 (after installing Nginx) sudo ufw enable sudo ufw status6Point your domain to the server
In your domain registrar's DNS panel add an A record for
@(andwww) with the server's public IP address. DNS changes usually appear within minutes but can take up to 24–48 hours. Check withdigor an online DNS checker.OUTPUT# Type Name Value TTL # A @ 203.0.113.10 3600 # A www 203.0.113.10 3600 dig +short example.com7Add free HTTPS with Let’s Encrypt
Certbot gets a free SSL certificate, adds it to the Nginx config and redirects HTTP to HTTPS. Certificates renew automatically (a systemd timer runs twice a day); test renewal once with
--dry-run.BASHsudo apt install -y certbot python3-certbot-nginx sudo certbot --nginx -d example.com -d www.example.com sudo certbot renew --dry-run8Set the Jenkins URL and security
Manage Jenkins → System → Jenkins URL =
https://jenkins.example.com/. In Security, keep “Jenkins’ own user database”, disable sign-up, use matrix-based permissions, and set the built-in node’s executors to 0 once agents are connected.9Back up jenkins_home
Stop-free backup of the volume to an archive you copy off the server.
BASHsudo docker run --rm -v jenkins_home:/data -v /backups:/backup alpine \ tar czf /backup/jenkins-$(date +%F).tgz -C /data .
🗺 The whole path from your code to the live site is drawn in the deployment diagram.
7. Images & screenshots
Illustrations drawn for this guide from the commands above. Product dashboards change often, so for screens such as cloud consoles follow the step text and the official documentation.
8. Common errors & solutions
npm: not found in a pipeline
The agent has no Node.js. Use a Docker agent (agent { docker { image 'node:lts' } }, needs the Docker Pipeline plugin and Docker on the agent) or install the NodeJS plugin/tool.
Webhook does not trigger builds
The URL must be public and end with /github-webhook/; the job needs the GitHub hook trigger enabled; check the webhook’s delivery log in GitHub.
Reverse proxy warning / broken links
Set the correct Jenkins URL and forward X-Forwarded-Proto/Host headers in Nginx.
Plugin dependency errors after updates
Update Jenkins core to the latest LTS first, then plugins; keep a backup of jenkins_home before upgrading.
Builds slow down the UI
Builds are running on the controller. Add agents and set the built-in node’s executors to 0.
Best practices
- Pipelines as code (Jenkinsfile) – no manual job configuration.
- Run builds on agents, not the controller.
- Keep Jenkins and plugins updated; remove unused plugins.
- Store secrets only in the Credentials store.
- Back up
jenkins_homeand test restoring it.