Skip to main content
In this guide, you’ll learn how to use the Jenkins CLI to build a job from your shell. The Jenkins CLI jar file is downloadable directly from your Jenkins instance. Navigate to Manage Jenkins, scroll down to the Jenkins CLI section, and follow the provided instructions. For additional details, refer to the official Jenkins documentation. You can start using the Jenkins CLI by downloading the CLI jar file from your Jenkins server. Simply copy the download URL and use it on your virtual machine. !!! note “Explore CLI Commands” To explore available CLI commands, you can run the following command, which displays an overview of all commands and options:
This command connects to your Jenkins instance at the specified URL using the downloaded jar file. The Jenkins CLI supports numerous commands similar to those available in the UI. If you’re unsure about a particular command, click it in the Jenkins UI to see additional examples and details.
The image shows a Jenkins CLI management interface with a list of commands and their descriptions, such as "list-plugins" and "offline-node."
For instance, to enable a job, the CLI documentation suggests using:
Replace NAME with the actual job name you wish to enable. Similarly, to build a project and review its parameters, use:

Downloading the Jenkins CLI

Download the Jenkins CLI jar file using wget. First, change to the root directory of your virtual machine and run:
The output should resemble:
After downloading, verify its presence with:
Expected output:

Running Basic CLI Commands

Once you have the jar file, you can run commands directly from the terminal or copy commands from the Jenkins UI. For example, to display all available CLI options, run:
This command shows usage options such as -s, -webSocket, -http, -ssh, and more. A helpful command is who-am-i, which reports your current authentication status:
Sample output:
Attempting to list jobs without the necessary permissions results in an error:
Output:
This error occurs because you’re accessing Jenkins as an anonymous user who lacks the required permissions.

Authenticating with the Jenkins CLI

To access protected data, authenticate with your username and password (or API token) using the -auth parameter:
If the credentials are valid and the user has required permissions, the command lists your Jenkins jobs:
You can also verify your authentication status:
Output:
!!! note “Authentication Tip” Always ensure you are using secure credentials. For improved security, consider using API tokens instead of plain-text passwords.

Building a Parameterized Pipeline Job

Building a project using the CLI is straightforward. The build command supports several options:
  • -c : Check for SCM changes before initiating the build.
  • -f : Follow the build progress.
  • -p : Pass build parameters in key-value format.
  • -s : Wait until the build completes or aborts.
  • -v : Display the console output.
  • -w : Wait until the build begins.
For example, to build a parameterized pipeline job with a branch parameter, use:
The command output may look like:
If you want to monitor the console output in real time, include the -v flag.
The image shows a Jenkins dashboard displaying the status of a parameterized pipeline job, with a test result trend graph and a detailed pipeline execution timeline.
While the shell logs progress messages, you might see output similar to:
After the build process, additional stages (such as integration tests) will run with logs output directly in the terminal.

Summary of Commands

Below is a table summarizing the most commonly used Jenkins CLI commands: In addition, you can run scripts or other CLI commands from your shell directory for further automation. For example, you might execute a shell script that calls:
which returns:
This guide only scratches the surface of what you can achieve with the Jenkins CLI—there are many more commands to explore. Experiment with different commands to get full control over your Jenkins instance.
The image shows a Jenkins CLI management interface with a list of commands and their descriptions. The interface includes options like "disconnect-node," "enable-job," and "get-credentials-as-xml."
Thank you for reading this article!

Watch Video