Jenkins cheatsheet
Service and access
| Check | Description |
|---|---|
systemctl status jenkins | Service status (package install) |
ss -tlnp | grep 8080 | Default HTTP port |
echo $JENKINS_HOME | Data directory |
cat /var/lib/jenkins/secrets/initialAdminPassword | First-time admin password |
CLI (jenkins-cli.jar)
wget -q $JENKINS_URL/jnlpJars/jenkins-cli.jar
java -jar jenkins-cli.jar -s $JENKINS_URL -auth user:token help
java -jar jenkins-cli.jar -s $JENKINS_URL list-jobs
java -jar jenkins-cli.jar -s $JENKINS_URL build JOB_NAME -s -v
Pipeline Jenkinsfile snippets
pipeline {
agent { label 'docker' }
environment {
REGISTRY = 'harbor.example.com/project'
}
stages {
stage('Checkout') {
steps { checkout scm }
}
stage('Build image') {
steps {
sh 'docker build -t $REGISTRY/app:$BUILD_NUMBER .'
}
}
stage('Push') {
steps {
withCredentials([usernamePassword(credentialsId: 'harbor', usernameVariable: 'U', passwordVariable: 'P')]) {
sh 'echo $P | docker login $REGISTRY -u $U --password-stdin'
sh 'docker push $REGISTRY/app:$BUILD_NUMBER'
}
}
}
}
}
Useful Groovy / steps
| Snippet | Description |
|---|---|
sh 'command' | Run shell on agent |
checkout scm | Clone configured SCM |
withCredentials([...]) { } | Inject secrets |
when { branch 'main' } | Conditional stage |
parallel { ... } | Concurrent stages |
timeout(time: 30, unit: 'MINUTES') | Stage timeout |
Agent and executor checks
# UI: Manage Jenkins → Nodes
# CLI:
java -jar jenkins-cli.jar -s $JENKINS_URL list-nodes
java -jar jenkins-cli.jar -s $JENKINS_URL get-node AGENT_NAME
Logs and disk
| Path / command | Description |
|---|---|
tail -f /var/log/jenkins/jenkins.log | Server log (Debian) |
journalctl -u jenkins -f | systemd journal |
du -sh $JENKINS_HOME/workspace/* | Workspace disk use |
| Build → Console Output | Per-build log in UI |
Safe restart
# UI: Manage Jenkins → Prepare for Shutdown / Restart
java -jar jenkins-cli.jar -s $JENKINS_URL safe-restart
# Or: systemctl restart jenkins (running builds may abort)
Pro tips
- Console Output is the first log to read on any failed build
- Pin plugins — document versions before upgrading Jenkins LTS
- Use labels (
agent { label 'linux' }) to target the right executors - Clean old builds and workspaces — disk fills silently under
JENKINS_HOME - Store secrets in Credentials, not in the Jenkinsfile in Git
Practice scenarios
Hands-on Jenkins scenarios on live Linux VMs: jenkins