Jenkins Basics & Installation
A comprehensive developer cheatsheet covering Jenkins fundamentals and installation, featuring essential CLI commands, master-agent architecture, initial setup workflows, and UI navigation.
What is Jenkins?
Jenkins is an open-source automation server used for building, testing, and deploying software. It is the most popular CI/CD (Continuous Integration / Continuous Delivery) tool.
Key Features
| Feature | Description |
|---|---|
| CI/CD Pipeline | Automate build, test, and deploy |
| Plugin Ecosystem | 1000+ plugins for integration |
| Distributed Builds | Master-agent architecture |
| Declarative & Scripted Pipelines | Code your CI/CD as code |
| Extensible | Custom plugins and integrations |
Jenkins Use Cases
- Automate build processes
- Run automated tests (unit, integration, acceptance)
- Deploy applications to staging/production
- Monitor build health and test results
- Trigger workflows based on code changes
Jenkins Architecture
Master-Agent Architecture
| Component | Description |
|---|---|
| Jenkins Master | Central controller, schedules jobs, stores configuration |
| Jenkins Agents | Run build jobs, execute tasks |
| Build Executors | Threads that run jobs on agents |
Components
┌─────────────────────────────────────────────────────────────┐
│ Jenkins Master │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ Job Scheduler │ Plugin Manager │ UI Server │ │
│ └─────────────────────────────────────────────────────┘ │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ Build Queue │ │
│ └─────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────┘
│
┌───────────────┼───────────────┐
▼ ▼ ▼
┌───────────┐ ┌───────────┐ ┌───────────┐
│ Agent 1 │ │ Agent 2 │ │ Agent 3 │
│ Linux │ │ Windows │ │ macOS │
└───────────┘ └───────────┘ └───────────┘Jenkins Installation
Installation Methods
| Method | Use Case | Command |
|---|---|---|
| Docker | Quick start, dev/test | docker run -p 8080:8080 jenkins/jenkins:lts |
| WAR File | Custom Java setup | java -jar jenkins.war |
| Linux Package | Production on Linux | sudo apt install jenkins |
| Windows Installer | Production on Windows | Download .msi installer |
| Kubernetes | Cloud-native | Helm charts |
Docker Installation (Quick Start)
# Pull and run Jenkins (LTS version)
$ docker run -p 8080:8080 -p 50000:50000 -v jenkins_home:/var/jenkins_home jenkins/jenkins:lts
# With volume for persistence
$ docker run -d \
--name jenkins \
-p 8080:8080 \
-p 50000:50000 \
-v jenkins_home:/var/jenkins_home \
jenkins/jenkins:lts
# View initial admin password
$ docker logs jenkinsLinux (Ubuntu/Debian) Installation
# Add 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
# Install Jenkins
$ sudo apt update
$ sudo apt install jenkins -y
# Start Jenkins
$ sudo systemctl start jenkins
$ sudo systemctl enable jenkins
# Check status
$ sudo systemctl status jenkinsInitial Setup
Step 1: Get Initial Admin Password
# Linux
$ sudo cat /var/lib/jenkins/secrets/initialAdminPassword
abc123def456...
# Docker
$ docker logs jenkinsStep 2: Access Jenkins Web UI
Open browser: http://localhost:8080
Step 3: Install Suggested Plugins
Click "Install suggested plugins" on the setup page.
Step 4: Create Admin User
Create the first admin user account.
Step 5: Set Jenkins URL
Set the Jenkins URL (default: http://localhost:8080).
Jenkins CLI Basics
Jenkins CLI Commands
| Command | Purpose | Example |
|---|---|---|
help | Show help | java -jar jenkins-cli.jar help |
version | Show version | java -jar jenkins-cli.jar version |
list-jobs | List all jobs | java -jar jenkins-cli.jar list-jobs |
build | Build a job | java -jar jenkins-cli.jar build my-job |
disable-job | Disable job | java -jar jenkins-cli.jar disable-job my-job |
enable-job | Enable job | java -jar jenkins-cli.jar enable-job my-job |
delete-job | Delete job | java -jar jenkins-cli.jar delete-job my-job |
get-job | Get job XML | java -jar jenkins-cli.jar get-job my-job > job.xml |
create-job | Create job from XML | cat job.xml | java -jar jenkins-cli.jar create-job my-job |
update-job | Update job from XML | cat job.xml | java -jar jenkins-cli.jar update-job my-job |
reload-configuration | Reload config | java -jar jenkins-cli.jar reload-configuration |
Using Jenkins CLI
Download Jenkins CLI:
$ wget http://localhost:8080/jnlpJars/jenkins-cli.jarRun CLI Commands:
# With username/password
$ java -jar jenkins-cli.jar -s http://localhost:8080 -auth admin:password list-jobs
# With SSH (if enabled)
$ ssh -l admin localhost -p 2222 helpJenkins CLI Examples
List all jobs:
$ java -jar jenkins-cli.jar -s http://localhost:8080 list-jobs
my-app-build
my-app-test
my-app-deployBuild a job:
$ java -jar jenkins-cli.jar -s http://localhost:8080 build my-app-buildBuild with parameters:
$ java -jar jenkins-cli.jar -s http://localhost:8080 build my-app-build -p BRANCH=developGet job XML:
$ java -jar jenkins-cli.jar -s http://localhost:8080 get-job my-app-build > my-app-build.xmlCreate job from XML:
$ cat my-app-build.xml | java -jar jenkins-cli.jar -s http://localhost:8080 create-job my-app-buildReload configuration:
$ java -jar jenkins-cli.jar -s http://localhost:8080 reload-configurationJenkins Web UI Overview
Key Sections
| Section | Description |
|---|---|
| Dashboard | Home page with job list |
| New Item | Create a new job or pipeline |
| Manage Jenkins | System configuration, plugins, security |
| Build Queue | Pending builds |
| Build Executor Status | Running builds |
| My Views | Custom dashboards |
| Credentials | Manage API keys, passwords, tokens |
Dashboard View
┌─────────────────────────────────────────────────────────────┐
│ Jenkins Dashboard │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ New Item │ Manage Jenkins │ Credentials │ │
│ └─────────────────────────────────────────────────────┘ │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ Build Queue │ Build Executor │ │
│ │ (0 builds pending) │ (2 executors) │ │
│ └─────────────────────────────────────────────────────┘ │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ Jobs │ │
│ │ ├── my-app-build │ (SVG) │ (Last: 5m) │ │
│ │ ├── my-app-test │ (SVG) │ (Last: 10m)│ │
│ │ └── my-app-deploy │ (SVG) │ (Last: 1h) │ │
│ └─────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────┘Manage Jenkins Sections
| Section | Description |
|---|---|
| System Configuration | Jenkins URL, global properties |
| Plugins | Manage plugins |
| Tools | JDK, Maven, Git, Gradle |
| Nodes | Manage agents |
| Credentials | Manage credentials |
| Security | Security settings |
| System Log | Jenkins logs |
| Script Console | Groovy scripts |
Quick Reference — Most Used Commands
| Task | Command |
|---|---|
| Start Jenkins (Docker) | docker run -p 8080:8080 jenkins/jenkins:lts |
| Start Jenkins (Linux) | sudo systemctl start jenkins |
| View initial password | sudo cat /var/lib/jenkins/secrets/initialAdminPassword |
| List jobs | java -jar jenkins-cli.jar list-jobs |
| Build job | java -jar jenkins-cli.jar build my-job |
| Build with params | java -jar jenkins-cli.jar build my-job -p BRANCH=develop |
| Get job XML | java -jar jenkins-cli.jar get-job my-job > job.xml |
| Create job from XML | cat job.xml | java -jar jenkins-cli.jar create-job my-job |
| Reload config | java -jar jenkins-cli.jar reload-configuration |
| Restart Jenkins | sudo systemctl restart jenkins |
Pro Tips
-
Initial Admin Password — saved in
/var/lib/jenkins/secrets/initialAdminPassword(Linux) orjenkins_homedirectory. -
Jenkins Home Directory — contains all job configurations, plugins, build history.
-
Backup Jenkins Home — for disaster recovery.
-
Use LTS Version — Long-Term Support is more stable for production.
-
Memory Requirements — Jenkins needs at least 256MB RAM (1GB+ recommended).
-
Docker Persistence — mount a volume for
jenkins_hometo persist data. -
Plugins — install only what you need to keep Jenkins fast.
-
Disable Demo/Example Jobs — remove them after setup.