Limited Time Offer!

For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!

Enroll Now

Know About Jenkins CLI | Jenkins CLI Guide

jenkins-cli

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

Rajesh Kumar
Follow me
Latest posts by Rajesh Kumar (see all)
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x