Find the Best Cosmetic Hospitals

Explore trusted cosmetic hospitals and make a confident choice for your transformation.

“Invest in yourself — your confidence is always worth it.”

Explore Cosmetic Hospitals

Start your journey today — compare options in one place.

Jenkins CLI Reference: Setup, Authentication, and Practical Command Examples

Jenkins CLI lets administrators and DevOps engineers run Jenkins operations from a terminal instead of clicking through the web UI. This guide explains how to download the matching CLI JAR from your Jenkins server, authenticate on secured instances, and use common commands for builds, jobs, and troubleshooting.

Originally published on 2014-02-10; fully revised and updated.

Jenkins CLI overview

What Jenkins CLI is useful for

Jenkins CLI is a command-line interface for interacting with a Jenkins controller. It is especially useful when you want repeatable admin operations in scripts, quick access over SSH sessions, or bulk updates that are slower in the UI.

  • Triggering builds with parameters
  • Reading build logs and job metadata
  • Creating, copying, and updating jobs from configuration XML
  • Managing nodes, queue state, and restart/shutdown operations

Download the matching jenkins-cli.jar from your Jenkins server

The original guidance is still valid: download the CLI JAR from your own Jenkins /cli endpoint so the CLI matches your server version. Jenkins typically exposes the file at /jnlpJars/jenkins-cli.jar.

# Check CLI page in a browser
http://yourserver.com/cli

# Download the matching jar from your Jenkins controller
curl -O http://yourserver.com/jnlpJars/jenkins-cli.jarCode language: PHP (php)

Basic command format and help

General syntax and help commands from the original article are below. Use these first when validating connectivity and permissions.

java -jar jenkins-cli.jar [-s JENKINS_URL] command [options...] [arguments...]

java -jar jenkins-cli.jar -s http://yourserver.com help
java -jar jenkins-cli.jar -s http://yourserver.com help buildCode language: JavaScript (javascript)

Authentication options for secured Jenkins

On secured Jenkins instances, unauthenticated commands may fail. The original post shows two direct methods (username/password and SSH private key), plus Jenkins CLI also supports credential caching via login/logout.

MethodCommand patternBest forOperational note
Username and password--username USER --password PASSQuick manual checksCredentials can be exposed in shell history/process lists.
SSH private key-i ~/.ssh/id_rsaUser accounts configured with Jenkins SSH public keysRequires correct key setup on the Jenkins user account.
Cached CLI credentiallogin then future commandsRepeated local CLI sessionsCredential storage behavior depends on local environment and Jenkins setup.
java -jar jenkins-cli.jar -s http://myjenkins help --username me --password mypassword
java -jar jenkins-cli.jar -s http://myjenkins help -i ~/.ssh/id_rsa

java -jar jenkins-cli.jar -s http://myjenkins login --username me --password mypassword
java -jar jenkins-cli.jar -s http://myjenkins who-am-iCode language: JavaScript (javascript)

Jenkins CLI command workflow

flowchart TD
    A[Set Jenkins URL] --> B[Download jenkins-cli.jar from server]
    B --> C[Run help command]
    C --> D{Jenkins secured}
    D -- no --> G[Run target command]
    D -- yes with user pass --> E[Authenticate with username password]
    D -- yes with SSH key --> F[Authenticate with private key]
    E --> G
    F --> G
    G --> H[Review output and exit status]
    H --> I[Adjust permissions or command flags]

Common Jenkins CLI commands by task

The original post includes a long command inventory. In practice, these are high-frequency commands that cover most daily automation and admin workflows.

TaskCommandExample
Trigger a jobbuildjava -jar jenkins-cli.jar -s http://myjenkins build "my-job"
Read console logsconsolejava -jar jenkins-cli.jar -s http://myjenkins console "my-job" 42
List jobslist-jobsjava -jar jenkins-cli.jar -s http://myjenkins list-jobs
Export job configget-jobjava -jar jenkins-cli.jar -s http://myjenkins get-job "my-job"
Update job configupdate-jobjava -jar jenkins-cli.jar -s http://myjenkins update-job "my-job"
Check identity and permswho-am-ijava -jar jenkins-cli.jar -s http://myjenkins who-am-i

Trigger a parameterized build

To pass build parameters via CLI, add one -p key=value for each parameter.

java -jar jenkins-cli.jar -s http://myjenkins build "Deploy XYZ App" -i ~/.ssh/id_rsa -p target_env=api.cloudfoundry.com -p branch=masterCode language: JavaScript (javascript)

Manage job XML from the terminal

These commands support export-edit-apply workflows for job definitions.

# Export a job config to file
java -jar jenkins-cli.jar -s http://myjenkins get-job "my-job" > my-job.xml

# Update a job config from file
java -jar jenkins-cli.jar -s http://myjenkins update-job "my-job" < my-job.xml

# Create a new job from XML
java -jar jenkins-cli.jar -s http://myjenkins create-job "my-new-job" < my-job.xmlCode language: PHP (php)

How to discover all commands on your own Jenkins

Because available commands can vary by Jenkins version and installed plugins, always inspect your own server output:

java -jar jenkins-cli.jar -s http://yourserver.com helpCode language: JavaScript (javascript)

Reference links from the original post

Best practices

  • Download jenkins-cli.jar from the same Jenkins server you target.
  • Validate access with help and who-am-i before running admin commands.
  • Prefer key-based authentication where possible, and avoid exposing secrets in shell history.
  • Treat restart/shutdown commands as change-controlled operations in production environments.
  • Generate command lists from your server because command availability can change across versions and plugins.

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services — all in one place.

Explore Hospitals
I'm Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms. I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.

Related Posts

Automating Jenkins Job Configuration: Job DSL, Multibranch, Job Generator, and JJB

Manually creating many Jenkins jobs is slow and error-prone. This guide compares the main automation options and shows practical jobs-as-code examples for repeatable setup.

Read More

Install Jenkins with Docker: Persistent Setup, Port Mapping, and Logs

Learn how to run Jenkins in Docker with correct port mapping, persistent storage, and operational commands. This updated guide keeps the original workflow but adds modern, production-minded practices.

Read More

Jenkins at Scale: Practical References and Admin Cheatsheet

This revised guide upgrades a short 2015 Jenkins link post into an operations-ready reference for teams running Jenkins at scale. It preserves the original links and adds a workflow diagram, comparison table, and practical API/CLI examples.

Read More

Jenkins Backup and Restore Runbook: ThinBackup, Filesystem Archives, and Recovery Steps

A practical Jenkins backup and restore guide for DevOps teams, covering what to back up, strategy trade-offs, and step-by-step command examples. Includes a workflow diagram and a recovery checklist you can operationalize.

Read More
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
0
Would love your thoughts, please comment.x
()
x