Skip to main content
Automating Jenkins tasks via the CLI and REST API delivers repeatability, consistency, and efficiency to your CI/CD pipelines. While the web UI is great for manual interactions, scripting with the Jenkins CLI (SSH or JAR) and the REST API enables you to integrate Jenkins seamlessly into your automation workflows.

Table of Contents

  1. Jenkins CLI over SSH
    1.1 Enable SSH Endpoint
    1.2 List Available Commands
    1.3 Trigger a Job via SSH
  2. Jenkins CLI Client (jenkins-cli.jar)
  3. Jenkins REST API
    3.1 Install a Plugin
    3.2 Authentication Methods
  4. References

Jenkins CLI over SSH

Jenkins includes a built-in CLI accessible over SSH. This approach avoids additional HTTP calls and works even behind strict firewalls.

Enable SSH Endpoint

By default, SSH is disabled. You can reveal the SSH endpoint with:
Next, add your SSH public key in Jenkins » People » YourUser » Configure.
Make sure your SSH key is correctly formatted (RFC4716 or OpenSSH) before pasting into Jenkins.

List Available Commands

Once SSH is configured, list all CLI commands:

Trigger a Job via SSH

Build a job named hello-kodekloud and stream console output:
Sample output:

Jenkins CLI Client (jenkins-cli.jar)

If SSH isn’t an option, download the jenkins-cli.jar from your Jenkins master:
Use HTTP or WebSocket transport:
Common commands:

Jenkins REST API

The Jenkins REST API provides HTTP endpoints for jobs, nodes, plugins, and more.

Install a Plugin

Use curl to install or update plugins:

Authentication Methods

Jenkins supports multiple authentication schemes. Use API tokens to avoid exposing plain passwords.
Never commit credentials or API tokens into version control. Use environment variables or secret managers.

References

Use these methods to automate job creation, builds, plugin management, and achieve consistent, repeatable CI/CD processes with Jenkins.

Watch Video