LinuxCommandLibrary

jenkins

Manage Jenkins automation server

TLDR

Connect to jenkins CLI

$ java -jar jenkins-cli.jar -s [jenkins_server_url] -auth [username]:[api_token]
copy

Restart jenkins
$ java -jar jenkins-cli.jar -s [jenkins_server_url] restart
copy

Shutdown jenkins
$ java -jar jenkins-cli.jar -s [jenkins_server_url] shutdown
copy

Display help
$ java -jar jenkins-cli.jar -s [jenkins_server_url] help
copy

Display version
$ java -jar jenkins-cli.jar -s [jenkins_server_url] version
copy

SYNOPSIS

jenkins [-s <URL>] [-auth <user:pass>] [--batch] [--strict] COMMAND [ARGS]

PARAMETERS

-s <URL>
    Jenkins controller URL.
Default: http://localhost:8080/

-auth @<FILE>
    Read credentials from file (user:pass or user:apitoken)

-auth <user:pass>
    Basic auth with username:password or username:API_token

--username <USER>
    Username for authentication

--password <PASS>
    Password or API token

--userId <USER>
    User ID for impersonation

--token <TOKEN>
    Session token

--batch
    Batch mode: suppress colors and interactive prompts

--strict
    Exit with non-zero code on stderr output

-remoting
    Use separate remoting JAR for execution

-f <FILE>
    Read command from file

-v, --version
    Print version info

-h, --help
    Show help

DESCRIPTION

Jenkins is an open-source automation server for continuous integration and continuous delivery (CI/CD). The jenkins command serves as the command-line interface (CLI) to manage and interact with a running Jenkins instance. Typically implemented as a wrapper for jenkins-cli.jar, it enables automation of tasks like triggering builds, querying job status, installing plugins, and administrative operations without the web UI.

Users download the CLI JAR from the Jenkins server (/jnlpJars/jenkins-cli.jar) and run it via Java. In package installations (e.g., Debian/Ubuntu), a jenkins script may be provided in /usr/bin. It supports remoting modes for executing commands on controller or agents, with authentication via basic auth, API tokens, or SSH. Ideal for scripting, DevOps pipelines, and headless environments.

Supports Groovy scripting, structured output (XML/JSON), and extensibility via plugins. Widely used in software development for build automation, testing, and deployment.

CAVEATS

Requires Java 8+ and a running Jenkins server.
CLI JAR must match server version.
Authentication often needs API token (not password).
Not installed by default; download from server.

COMMON COMMANDS

help - list commands
who-am-i - current user
list-jobs - list jobs
build JOB [-p] - trigger build (with params)
console JOB #N - get console output

INSTALLATION NOTE

Download: wget http://server:8080/jnlpJars/jenkins-cli.jar
Run: java -jar jenkins-cli.jar -s http://server:8080/ help

HISTORY

CLI introduced in Jenkins 1.308 (2010).
Jenkins forked from Oracle's Hudson project in 2011 by Kohsuke Kawaguchi.
CLI evolved with JNLP/remoting support; modern versions emphasize API tokens over passwords.

SEE ALSO

java(1), systemctl(1), curl(1), groovy(1)

Copied to clipboard