Skip to content

Instantly share code, notes, and snippets.

@cyrille-leclerc
Last active January 26, 2024 17:53
Show Gist options
  • Save cyrille-leclerc/6c46e5f800236cb324d10d9c7e8f9bb1 to your computer and use it in GitHub Desktop.
Save cyrille-leclerc/6c46e5f800236cb324d10d9c7e8f9bb1 to your computer and use it in GitHub Desktop.
CloudBees Jenkins Master CLI Commands

CREATE GROUP

java -jar jenkins-cli.jar ... help create-group
java -jar jenkins-cli.jar create-group CONTAINER GROUP
Creates a groups
 CONTAINER : root | path/to/job-or-folder | path/to/folder/view-name |
             slave-name

CREATE CREDENTIALS BY XML

java -jar jenkins-cli.jar ... help create-credentials-by-xml
java -jar jenkins-cli.jar create-credentials-by-xml STORE DOMAIN
Create Credential by XML
 STORE  : Store Id
 DOMAIN : Domain Name

CREATE JOB

java -jar jenkins-cli.jar ... help create-job
java -jar jenkins-cli.jar create-job NAME
Creates a new job by reading stdin as a configuration XML file.
 NAME : Name of the job to create

GROUP ROLES ASSIGNEMENTS

java -jar jenkins-cli.jar ... help group-role-assignments
java -jar jenkins-cli.jar group-role-assignments CONTAINER GROUP [ROLES ...] [-e (--expanded-display)]
Displays or sets group role assignments.
 CONTAINER : root | path/to/job-or-folder | path/to/folder/view-name |
             slave-name
 ROLES     : ROLE[,GRANTED_AT[,PROPAGATES]]  GRANTED_AT=0|1|2  (0:current
             level, 1: Child level, 2: Grand child level), PROPAGATES=true|false

GROUP MEMBERSHIP

java -jar jenkins-cli.jar ... help group-membership
java -jar jenkins-cli.jar group-membership CONTAINER GROUP [MEMBERS ...]
Displays or sets the membership of a group.
 CONTAINER : root | path/to/job-or-folder | path/to/folder/view-name |
             slave-name

LOGIN

java -jar jenkins-cli.jar ... help login
java -jar jenkins-cli.jar login
Saves the current credentials to allow future commands to run without explicit credential information. [deprecated]
Depending on the security realm, you will need to pass something like:
--username USER [ --password PASS | --password-file FILE ]
May not be supported in some security realms, such as single-sign-on.
Pair with the logout command.
The same options can be used on any other command, but unlike other generic CLI options,
these come *after* the command name.
Whether stored or not, this authentication mode will not let you refer to (e.g.) jobs as arguments
if Jenkins denies anonymous users Overall/Read and (e.g.) Job/Read.
*Deprecated* in favor of -auth.

JENKINS CLI PARAMS

java -jar jenkins-cli.jar
Neither -s nor the JENKINS_URL env var is specified.
Jenkins CLI
Usage: java -jar jenkins-cli.jar [-s URL] command [opts...] args...
Options:
-s URL       : the server URL (defaults to the JENKINS_URL env var)
-http        : use a plain CLI protocol over HTTP(S) (the default; mutually exclusive with -ssh and -remoting)
-ssh         : use SSH protocol (requires -user; SSH port must be open on server, and user must have registered a public key)
-remoting    : use deprecated Remoting channel protocol (if enabled on server; for compatibility with legacy commands or command modes only)
-i KEY       : SSH private key file used for authentication (for use with -ssh or -remoting)
-p HOST:PORT : HTTP proxy host and port for HTTPS proxy tunneling. See https://jenkins.io/redirect/cli-https-proxy-tunnel
-noCertificateCheck : bypass HTTPS certificate check entirely. Use with caution
-noKeyAuth   : dont try to load the SSH authentication private key. Conflicts with -i
-user        : specify user (for use with -ssh)
-strictHostKey : request strict host key checking (for use with -ssh)
-logger FINE : enable detailed logging from the client
-auth [ USER:SECRET | @FILE ] : specify username and either password or API token (or load from them both from a file);
for use with -http, or -remoting but only when the JNLP agent port is disabled

The available commands depend on the server. Run the help command to
see the list.

java -jar jenkins-cli.jar create-credentials-by-xml STORE DOMAIN

java -jar jenkins-cli.jar ... help
add-job-to-view
Adds jobs to view.
apply-folder-skip
Enable the skip setting on a folder.
apply-skip
Enable the skip setting on a job.
approve-controlled-slaves-request
Approved a request key for a folder to use the node as a controlled slave
build
Builds a job, and optionally waits until its completion.
cancel-quiet-down
Cancel the effect of the "quiet-down" command.
check-alert-condition
Checks if the specified alert is currently active.
cjp-copy-item
Copy an item to another CloudBees Jenkins Platform location.
cjp-move-item
Move an item to another CloudBees Jenkins Platform location.
cjp-promote-item
Promote an item to another CloudBees Jenkins Platform location.
clear-queue
Clears the build queue.
complete-controlled-slaves-request
Generates a request key for controlled slaves
connect-node
Reconnect to a node(s)
console
Retrieves console output of a build.
copy-job
Copies a job.
create-controlled-slaves-request
Generates a request key for controlled slaves
create-credentials-by-xml
Create Credential by XML
create-credentials-domain-by-xml
Create Credentials Domain by XML
create-group
Creates a groups
create-job
Creates a new job by reading stdin as a configuration XML file.
create-node
Creates a new node by reading stdin as a XML configuration.
create-view
Creates a new view by reading stdin as a XML configuration.
declarative-linter
Validate a Jenkinsfile containing a Declarative Pipeline
delete-builds
Deletes build record(s).
delete-controlled-slave
Remove a controlled slave from the folder
delete-credentials
Delete a Credential
delete-credentials-domain
Delete a Credentials Domain
delete-group
Deletes a groups
delete-job
Deletes job(s).
delete-node
Deletes node(s)
delete-token
Remove a token and all associated folders from the list of allowed folders
delete-view
Deletes view(s).
disable-job
Disables a job.
disconnect-node
Disconnects from a node.
enable-job
Enables a job.
get-credentials-as-xml
Get a Credentials as XML (secrets redacted)
get-credentials-domain-as-xml
Get a Credentials Domain as XML
get-job
Dumps the job definition XML to stdout.
get-node
Dumps the node definition XML to stdout.
get-view
Dumps the view definition XML to stdout.
groovy
Executes the specified Groovy script.
groovysh
Runs an interactive groovy shell.
group-membership
Displays or sets the membership of a group.
group-role-assignments
Displays or sets group role assignments.
help
Lists all the available commands or a detailed description of single command.
install-plugin
Installs a plugin either from a file, an URL, or from update center.
install-tool
Performs automatic tool installation, and print its location to stdout. Can be only called from inside a build. [deprecated]
instantiate
Creates or updates an instance of a template.
keep-build
Mark the build to keep the build forever.
list-alert-conditions
Lists the alert conditions and their statuses.
list-changes
Dumps the changelog for the specified build(s).
list-credentials
Lists the Credentials in a specific Store
list-credentials-context-resolvers
List Credentials Context Resolvers
list-credentials-providers
List Credentials Providers
list-groups
Lists groups.
list-jobs
Lists all jobs in a specific view or item group.
list-plugins
Outputs a list of installed plugins.
login
Saves the current credentials to allow future commands to run without explicit credential information. [deprecated]
logout
Deletes the credentials stored with the login command. [deprecated]
mail
Reads stdin and sends that out as an e-mail.
mute-alert-condition
Mutes the specified alert condition.
offline-node
Stop using a node for performing builds temporarily, until the next "online-node" command.
online-node
Resume using a node for performing builds, to cancel out the earlier "offline-node" command.
quiet-down
Quiet down Jenkins, in preparation for a restart. Don’t start any builds.
reload-configuration
Discard all the loaded data in memory and reload everything from file system. Useful when you modified config files directly on disk.
reload-job
Reload job(s)
remove-folder-skip
Remove the currently in-effect skip setting from a folder.
remove-job-from-view
Removes jobs from view.
remove-skip
Remove the currently in-effect skip setting from a job.
replay-pipeline
Replay a Pipeline build with edited script taken from standard input
restart
Restart Jenkins.
restart-checkpoint
Restart a build from a checkpoint.
safe-restart
Safely restart Jenkins.
safe-shutdown
Puts Jenkins into the quiet mode, wait for existing builds to be completed, and then shut down Jenkins.
session-id
Outputs the session ID, which changes every time Jenkins restarts.
set-build-description
Sets the description of a build.
set-build-display-name
Sets the displayName of a build.
set-build-parameter
Update/set the build parameter of the current build in progress. [deprecated]
set-build-result
Sets the result of the current build. Works only if invoked from within a build. [deprecated]
set-external-build-result
Set external monitor job result.
shutdown
Immediately shuts down Jenkins server.
skip-group-off
Turn a skip group off.
skip-group-on
Turn a skip group on.
support
Generates a diagnostic support bundle.
unmute-alert-condition
Unmutes the specified alert condition.
update-credentials-by-xml
Update Credentials by XML
update-credentials-domain-by-xml
Update Credentials Domain by XML
update-job
Updates the job definition XML from stdin. The opposite of the get-job command.
update-node
Updates the node definition XML from stdin. The opposite of the get-node command.
update-view
Updates the view definition XML from stdin. The opposite of the get-view command.
version
Outputs the current version.
wait-node-offline
Wait for a node to become offline.
wait-node-online
Wait for a node to become online.
who-am-i
Reports your credential and permissions.

CREATE CONTROLLED SLAVES REQUEST

java -jar jenkins-cli.jar ... help create-controlled-slaves-request
java -jar jenkins-cli.jar create-controlled-slaves-request FOLDER
Generates a request key for controlled slaves
 FOLDER : Name of the folder

APPROVE CONTROLLED SLAVES REQUEST

java -jar jenkins-cli.jar ... help approve-controlled-slaves-request
java -jar jenkins-cli.jar approve-controlled-slaves-request NAME KEY
Approved a request key for a folder to use the node as a controlled slave
 NAME : Slave name, or empty string for master
 KEY  : Request Key

COMPLETE CONTROLLED SLAVES REQUEST

java -jar jenkins-cli.jar ... help complete-controlled-slaves-request
java -jar jenkins-cli.jar complete-controlled-slaves-request FOLDER KEY SECRET
Generates a request key for controlled slaves
 FOLDER : Name of the folder
 KEY    : Request Key
 SECRET : Request Secret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment