If you’re managing Jenkins pipelines daily, this Jenkins CLI Cheat Sheet is your go-to resource. The Jenkins Command Line Interface (CLI) is a powerful way to automate tasks, manage jobs, and interact with your Jenkins server without needing the web UI. Whether you’re a DevOps engineer or a CI/CD beginner, mastering the Jenkins CLI boosts your productivity and helps streamline automation workflows.
What Is Jenkins CLI?
The Jenkins CLI (Command Line Interface) allows you to perform most administrative and operational tasks using terminal commands instead of the web dashboard. It’s ideal for scripting repetitive tasks, automating deployments, or managing Jenkins remotely.
With Jenkins CLI, you can:
- Trigger builds and view job statuses.
- Manage plugins, users, and configurations.
- Execute groovy scripts remotely.
- Handle nodes, credentials, and queue management.
Jenkins CLI can be used locally or remotely over SSH or HTTP, making it flexible for both cloud and on-premise setups.
How to Access Jenkins CLI
Before diving into this Jenkins CLI Cheat Sheet, let’s see how you can access it.
1. Using the Jenkins Web Interface
You can download the CLI JAR file directly from your Jenkins server:
https://<your-jenkins-url>/jnlpJars/jenkins-cli.jar
Save this file in your working directory.
2. Running Jenkins CLI Commands
You can execute commands like this:
java -jar jenkins-cli.jar -s http://localhost:8080/ help
Or connect with authentication:
java -jar jenkins-cli.jar -s http://localhost:8080/ -auth user:token list-jobs
3. Using SSH
If Jenkins allows SSH, connect with:
ssh -l user -p 22 jenkins@jenkins-server help
Using SSH removes the need to manage authentication tokens separately.
Setting Up Jenkins CLI Authentication
Authentication ensures secure access to Jenkins resources. You can authenticate in two main ways:
1. Username and API Token
Create an API token from:
Manage Jenkins → Manage Users → <Your User> → Configure → API Token
Then use:
java -jar jenkins-cli.jar -s http://localhost:8080/ -auth user:token list-jobs
2. SSH Key Authentication
For SSH-enabled Jenkins servers, add your public key in:
Manage Jenkins → Configure Global Security → SSH Public Keys
Then simply connect:
ssh -l user jenkins@jenkins-serverBasic Jenkins CLI Commands
The following section of this Jenkins CLI Cheat Sheet covers essential commands every DevOps engineer should know.
1. Help Command
Display all available commands:
java -jar jenkins-cli.jar -s http://localhost:8080/ help
2. List All Jobs
java -jar jenkins-cli.jar -s http://localhost:8080/ list-jobs
3. Build a Job
Trigger a Jenkins build:
java -jar jenkins-cli.jar -s http://localhost:8080/ build MyJob
To pass parameters:
java -jar jenkins-cli.jar -s http://localhost:8080/ build MyJob -p key=value
4. Check Build Status
java -jar jenkins-cli.jar -s http://localhost:8080/ get-job MyJob
5. Enable or Disable a Job
java -jar jenkins-cli.jar -s http://localhost:8080/ enable-job MyJob
java -jar jenkins-cli.jar -s http://localhost:8080/ disable-job MyJobJenkins CLI Job Management Commands
Managing Jenkins jobs via CLI can be faster than using the GUI, especially for large pipelines.
1. Create a New Job
java -jar jenkins-cli.jar -s http://localhost:8080/ create-job NewJob < config.xml
2. Copy a Job
java -jar jenkins-cli.jar -s http://localhost:8080/ copy-job OldJob NewJob
3. Delete a Job
java -jar jenkins-cli.jar -s http://localhost:8080/ delete-job MyJob
4. Rename a Job
java -jar jenkins-cli.jar -s http://localhost:8080/ rename-job OldName NewNameBuild Queue and Node Management Commands
1. List Nodes
java -jar jenkins-cli.jar -s http://localhost:8080/ list-computers
2. Disconnect a Node
java -jar jenkins-cli.jar -s http://localhost:8080/ disconnect-node NodeName
3. Connect a Node
java -jar jenkins-cli.jar -s http://localhost:8080/ connect-node NodeName
4. Manage Queue
java -jar jenkins-cli.jar -s http://localhost:8080/ list-queue
java -jar jenkins-cli.jar -s http://localhost:8080/ cancel-queue <id>Plugin Management Using Jenkins CLI
Plugins are critical in Jenkins. This Jenkins CLI Cheat Sheet includes commands for plugin operations.
1. List Installed Plugins
java -jar jenkins-cli.jar -s http://localhost:8080/ list-plugins
2. Install a Plugin
java -jar jenkins-cli.jar -s http://localhost:8080/ install-plugin git
3. Update Plugins
java -jar jenkins-cli.jar -s http://localhost:8080/ safe-restart
4. Remove a Plugin
java -jar jenkins-cli.jar -s http://localhost:8080/ uninstall-plugin plugin-nameJenkins CLI Script Console and Groovy Commands
The script console is one of the most powerful Jenkins CLI features.
1. Execute Groovy Script
java -jar jenkins-cli.jar -s http://localhost:8080/ groovy = < script.groovy
2. Run Inline Groovy Script
java -jar jenkins-cli.jar -s http://localhost:8080/ groovysh "println Jenkins.instance.getItemByManaging Credentials via CLI
While sensitive, some credential management operations can be done safely through CLI.
1. Export Credentials
java -jar jenkins-cli.jar -s http://localhost:8080/ get-credentials domain
2. Import Credentials
java -jar jenkins-cli.jar -s http://localhost:8080/ create-credentials-domain < domain.xmlBackup and Restore Using Jenkins CLI
You can automate Jenkins backup using CLI commands and scripts.
1. Backup Jobs and Configurations
java -jar jenkins-cli.jar -s http://localhost:8080/ get-job MyJob > backup-MyJob.xml
2. Restore Jobs
java -jar jenkins-cli.jar -s http://localhost:8080/ create-job MyJob < backup-MyJob.xml
Automating this process helps maintain disaster recovery readiness.
Automating Jenkins CLI Commands
You can combine multiple commands into shell scripts for automation.
Example script to trigger builds and check status:
#!/bin/bash
JENKINS_URL="http://localhost:8080/"
JAR="jenkins-cli.jar"
AUTH="user:token"
java -jar $JAR -s $JENKINS_URL -auth $AUTH build MyJob
java -jar $JAR -s $JENKINS_URL -auth $AUTH console MyJob
This automation approach is ideal for CI/CD pipelines, cron jobs, or Jenkins management scripts.
Troubleshooting Jenkins CLI
If you encounter issues, use these troubleshooting steps:
- Connection Errors → Check Jenkins URL and port.
- Auth Failures → Verify API token or SSH key.
- Command Not Found → Ensure you’re using the latest CLI JAR version.
- SSL Issues → Use
-noCertificateCheckfor local testing only.
Example:
java -jar jenkins-cli.jar -noCertificateCheck -s https://jenkins-server/ list-jobsBest Practices for Using Jenkins CLI
- Use API tokens instead of passwords.
- Avoid storing credentials in plain text.
- Automate routine maintenance tasks.
- Regularly back up job configurations.
- Limit access to trusted administrators only.
Following these best practices keeps your Jenkins instance secure and efficient.
Conclusion
This Jenkins CLI Cheat Sheet gives you a complete command reference to manage Jenkins more effectively. From automating builds to managing plugins, the CLI makes DevOps workflows smoother and faster. Keep this cheat sheet handy for everyday Jenkins administration or scripting automation tasks.
With consistent usage, you’ll master Jenkins CLI commands that reduce manual effort and increase productivity.
FAQs about Jenkins CLI Cheat Sheet
1. What is the Jenkins CLI used for?
The Jenkins CLI allows administrators and developers to execute Jenkins operations—like building jobs, managing plugins, and viewing configurations—directly from the command line.
2. How do I download Jenkins CLI?
You can download jenkins-cli.jar from:http://<your-jenkins-url>/jnlpJars/jenkins-cli.jar
3. Can I use Jenkins CLI remotely?
Yes. Jenkins CLI supports remote connections via HTTP or SSH, allowing you to manage Jenkins servers without accessing the web UI.
4. Is Jenkins CLI secure?
Yes, when used with API tokens or SSH authentication. Avoid using plain text passwords to enhance security.
5. What’s the difference between Jenkins REST API and CLI?
The REST API is used for integration with other tools or scripts, while the CLI is designed for command-based interaction and administration.