Know About Jenkins CLI

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

Getting help
java -jar jenkins-cli.jar -s yourserver.com help [command]

How to download jenkins-cli.jar?
The best place to download the Jenkins CLI jar is from your own Jenkins server. This means you’ll have the matching CLI version. Visit the /cli endpoint, such as http://yourserver.com/cli, and it will give you a link to download the jar (the /jnlpJars/jenkins-cli.jar endpoint). Download that jar.

Running commands against a secure Jenkins (basic auth or ssh keys)

If your Jenkins is secured, and it probably is so that you control who can create jobs, run jobs, view results, then the command above may fail and ask for credentials.
You have two options: provide --username & --password options to every command or provide -i option and provide the path to the ssh private key that matches the public key you provided to your user account.
For example:

$ 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

Passing parameters when triggering a job build
To pass those same parameters via the CLI? You use the -p key=value flag for each parameter you want to pass.

So our finished product might look like:

$ java -jar jenkins-cli.jar -s http://myjenkins build 'Deploy XYZ App' -i ~/.ssh/id_rsa -s -v -p target_env=api.cloudfoundry.com -p branch=master

How to get all commands for Jenkins CLI-
Run > http://yourserver.com/cli

java -jar jenkins-cli.jar -s http://fmsscm.corp.intuit.net/qbo-qa/ help

Available Commands

  • build: Builds a job, and optionally waits until its completion.
  • cancel-quiet-down: Cancel the effect of the "quiet-down" command.
  • clear-queue: Clears the build queue
  • connect-node: Reconnect to a node
  • console: Retrieves console output of a build
  • copy-job: Copies a job.
  • 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.
  • delete-builds: Deletes build record(s).
  • delete-job: Deletes a job
  • delete-node: Deletes a node
  • disable-job: Disables a job
  • disconnect-node: Disconnects from a node
  • enable-job: Enables a job
  • get-job: Dumps the job definition XML to stdout
  • get-node: Dumps the node definition XML to stdout
  • groovy: Executes the specified Groovy script.
  • groovysh: Runs an interactive groovy shell.
  • help: Lists all the available commands.
  • 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.
  • keep-build: Mark the build to keep the build forever.
  • list-changes: Dumps the changelog for the specified build(s).
  • list-jobs: Lists all jobs in a specific view or item group.
  • list-plugins: Outputs a list of installed plugins.
  • login: Saves the current credential to allow future commands to run without explicit credential information.
  • logout: Deletes the credential stored with the login command.
  • mail: Reads stdin and sends that out as an e-mail.
  • 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.
  • restart: Restart Jenkins
  • 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
  • set-build-result: Sets the result of the current build. Works only if invoked from within a build.
  • set-external-build-result: Set external monitor job result.
  • set-next-build-number: Set build number to be used for next build.
  • shutdown: Immediately shuts down Jenkins server
  • 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
  • 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

Reference –
https://wiki.jenkins-ci.org/display/JENKINS/Jenkins+CLI
http://stackoverflow.com/questions/18199355/jenkins-cli-authentication
http://stackoverflow.com/questions/16617232/jenkins-cli-public-key-authentication-where-to-put-my-public-key-in-jenkins

Rate this item
(0 votes)
Rajesh Kumar

.

Total, Over 12 years of extensive experience in the Software Configuration Management domain having depth knowledge of DevOps, Continuous Integration and Delivery, Configuration Management, Build and Installer, Release Management and Application Management.

More in this category:

What corporate management say about us?

Rajesh is very knowledgeable instructor he has a good exposure on real time issue and case studies he is experienced in large environment issue and challenges. I really liked how Rajesh used a lot of examples so that concepts were more easily understood, I like the examples that Rajesh give to help us remember things…they are usually real scenario, real life problems that we encounter frequently. <br /> He is well organised in terms of study materiel that you can refer anytime after you complete your course. His blogs are crisp and has to the point key content that he discussed during session to remember if you refer them remotely.

Gaurav Vishnoi
I am having 11+ years of experience in java, due to increasing complexity of system and environment I opted for this tanning and find it very useful., Noida
Sep 02, 2016

Authors

Login