{"id":346,"date":"2014-02-10T04:16:10","date_gmt":"2014-02-10T04:16:10","guid":{"rendered":"http:\/\/www.scmgalaxy.com\/tutorials\/2014\/02\/10\/know-about-jenkins-cli\/"},"modified":"2021-11-19T09:29:09","modified_gmt":"2021-11-19T09:29:09","slug":"know-about-jenkins-cli","status":"publish","type":"post","link":"https:\/\/www.devopsschool.com\/blog\/know-about-jenkins-cli\/","title":{"rendered":"Know About Jenkins CLI | Jenkins CLI Guide"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3748 aligncenter\" src=\"http:\/\/www.scmgalaxy.com\/tutorials\/wp-content\/uploads\/2014\/02\/jenkins-cli.png\" alt=\"jenkins-cli\" width=\"600\" height=\"400\" srcset=\"https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2014\/02\/jenkins-cli.png 600w, https:\/\/www.devopsschool.com\/blog\/wp-content\/uploads\/2014\/02\/jenkins-cli-300x200.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><\/p>\n<p><strong>Running CLI<\/strong><br>\njava -jar jenkins-cli.jar [-s JENKINS_URL] command [options&#8230;] [arguments&#8230;]<\/p>\n<p><strong>Getting help<\/strong><br>\njava -jar jenkins-cli.jar -s yourserver.com help [command]<\/p>\n<p><strong>How to download jenkins-cli.jar?<\/strong><br>\nThe best place to download the Jenkins CLI jar is from your own Jenkins server. This means you\u2019ll 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.<\/p>\n<p><strong>Running commands against a secure Jenkins (basic auth or ssh keys)<\/strong><\/p>\n<p>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.<br>\nYou have two options: provide &#8211;username &amp; &#8211;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.<br>\nFor example:<\/p>\n<p>$ java -jar jenkins-cli.jar -s http:\/\/myjenkins help &#8211;username me &#8211;password mypassword<br>\n$ java -jar jenkins-cli.jar -s http:\/\/myjenkins help -i ~\/.ssh\/id_rsa<\/p>\n<p><strong>Passing parameters when triggering a job build<\/strong><br>\nTo pass those same parameters via the CLI? You use the -p key=value flag for each parameter you want to pass.<\/p>\n<p>So our finished product might look like:<\/p>\n<p>$ java -jar jenkins-cli.jar -s http:\/\/myjenkins build &#8216;Deploy XYZ App&#8217; -i ~\/.ssh\/id_rsa -s -v -p target_env=api.cloudfoundry.com -p branch=master<\/p>\n<p>How to get all commands for Jenkins CLI-<br>\nRun &gt; <a href=\"http:\/\/yourserver.com\/cli\" target=\"_blank\" rel=\"noopener\">http:\/\/yourserver.com\/cli<\/a><\/p>\n<p><strong>java -jar <a href=\"http:\/\/fmsscm.corp.intuit.net\/qbo-qa\/jnlpJars\/jenkins-cli.jar\" target=\"_blank\" rel=\"noopener\">jenkins-cli.jar<\/a> -s http:\/\/fmsscm.corp.intuit.net\/qbo-qa\/ help<\/strong><\/p>\n<h2>Available Commands<\/h2>\n<ul type=\"disc\">\n<li><strong>build<\/strong>: Builds a job, and optionally waits until its completion.<\/li>\n<li><strong>cancel-quiet-down<\/strong>: Cancel the effect of the &#8220;quiet-down&#8221; command.<\/li>\n<li><strong>clear-queue<\/strong>: Clears the build queue<\/li>\n<li><strong>connect-node<\/strong>: Reconnect to a node<\/li>\n<li><strong>console<\/strong>: Retrieves console output of a build<\/li>\n<li><strong>copy-job<\/strong>: Copies a job.<\/li>\n<li><strong>create-job<\/strong>: Creates a new job by reading stdin as a configuration XML file.<\/li>\n<li><strong>create-node<\/strong>: Creates a new node by reading stdin as a XML configuration.<\/li>\n<li><strong>delete-builds<\/strong>: Deletes build record(s).<\/li>\n<li><strong>delete-job<\/strong>: Deletes a job<\/li>\n<li><strong>delete-node<\/strong>: Deletes a node<\/li>\n<li><strong>disable-job<\/strong>: Disables a job<\/li>\n<li><strong>disconnect-node<\/strong>: Disconnects from a node<\/li>\n<li><strong>enable-job<\/strong>: Enables a job<\/li>\n<li><strong>get-job<\/strong>: Dumps the job definition XML to stdout<\/li>\n<li><strong>get-node<\/strong>: Dumps the node definition XML to stdout<\/li>\n<li><strong>groovy<\/strong>: Executes the specified Groovy script.<\/li>\n<li><strong>groovysh<\/strong>: Runs an interactive groovy shell.<\/li>\n<li><strong>help<\/strong>: Lists all the available commands.<\/li>\n<li><strong>install-plugin<\/strong>: Installs a plugin either from a file, an URL, or from update center.<\/li>\n<li><strong>install-tool<\/strong>: Performs automatic tool installation, and print its location to stdout. Can be only called from inside a build.<\/li>\n<li><strong>keep-build<\/strong>: Mark the build to keep the build forever.<\/li>\n<li><strong>list-changes<\/strong>: Dumps the changelog for the specified build(s).<\/li>\n<li><strong>list-jobs<\/strong>: Lists all jobs in a specific view or item group.<\/li>\n<li><strong>list-plugins<\/strong>: Outputs a list of installed plugins.<\/li>\n<li><strong>login<\/strong>: Saves the current credential to allow future commands to run without explicit credential information.<\/li>\n<li><strong>logout<\/strong>: Deletes the credential stored with the login command.<\/li>\n<li><strong>mail<\/strong>: Reads stdin and sends that out as an e-mail.<\/li>\n<li><strong>offline-node<\/strong>: Stop using a node for performing builds temporarily, until the next &#8220;online-node&#8221; command.<\/li>\n<li><strong>online-node<\/strong>: Resume using a node for performing builds, to cancel out the earlier &#8220;offline-node&#8221; command.<\/li>\n<li><strong>quiet-down<\/strong>: Quiet down Jenkins, in preparation for a restart. Don\u2019t start any builds.<\/li>\n<li><strong>reload-configuration<\/strong>: Discard all the loaded data in memory and reload everything from file system. Useful when you modified config files directly on disk.<\/li>\n<li><strong>restart<\/strong>: Restart Jenkins<\/li>\n<li><strong>safe-restart<\/strong>: Safely restart Jenkins<\/li>\n<li><strong>safe-shutdown<\/strong>: Puts Jenkins into the quiet mode, wait for existing builds to be completed, and then shut down Jenkins.<\/li>\n<li><strong>session-id<\/strong>: Outputs the session ID, which changes every time Jenkins restarts<\/li>\n<li><strong>set-build-description<\/strong>: Sets the description of a build.<\/li>\n<li><strong>set-build-display-name<\/strong>: Sets the displayName of a build<\/li>\n<li><strong>set-build-parameter<\/strong>: Update\/set the build parameter of the current build in progress<\/li>\n<li><strong>set-build-result<\/strong>: Sets the result of the current build. Works only if invoked from within a build.<\/li>\n<li><strong>set-external-build-result<\/strong>: Set external monitor job result.<\/li>\n<li><strong>set-next-build-number<\/strong>: Set build number to be used for next build.<\/li>\n<li><strong>shutdown<\/strong>: Immediately shuts down Jenkins server<\/li>\n<li><strong>update-job<\/strong>: Updates the job definition XML from stdin. The opposite of the get-job command<\/li>\n<li><strong>update-node<\/strong>: Updates the node definition XML from stdin. The opposite of the get-node command<\/li>\n<li><strong>version<\/strong>: Outputs the current version.<\/li>\n<li><strong>wait-node-offline<\/strong>: Wait for a node to become offline<\/li>\n<li><strong>wait-node-online<\/strong>: Wait for a node to become online<\/li>\n<li><strong>who-am-i<\/strong>: Reports your credential and permissions<\/li>\n<\/ul>\n<p><strong>Reference \u2013<\/strong><br>\n<a href=\"https:\/\/wiki.jenkins-ci.org\/display\/JENKINS\/Jenkins+CLI\" target=\"_blank\" rel=\"noopener\">https:\/\/wiki.jenkins-ci.org\/display\/JENKINS\/Jenkins+CLI<\/a><br>\n<a href=\"http:\/\/stackoverflow.com\/questions\/18199355\/jenkins-cli-authentication\" target=\"_blank\" rel=\"noopener\">http:\/\/stackoverflow.com\/questions\/18199355\/jenkins-cli-authentication<\/a><br>\n<a href=\"http:\/\/stackoverflow.com\/questions\/16617232\/jenkins-cli-public-key-authentication-where-to-put-my-public-key-in-jenkins\" target=\"_blank\" rel=\"noopener\">http:\/\/stackoverflow.com\/questions\/16617232\/jenkins-cli-public-key-authentication-where-to-put-my-public-key-in-jenkins<\/a><\/p>\n\n<div class=\"epyt-gallery\" data-currpage=\"1\" id=\"epyt_gallery_87445\"><iframe loading=\"lazy\"  id=\"_ytid_36786\"  width=\"760\" height=\"427\"  data-origwidth=\"760\" data-origheight=\"427\" src=\"https:\/\/www.youtube.com\/embed\/?enablejsapi=1&#038;autoplay=0&#038;cc_load_policy=0&#038;cc_lang_pref=&#038;iv_load_policy=1&#038;loop=0&#038;rel=1&#038;fs=1&#038;playsinline=0&#038;autohide=2&#038;theme=dark&#038;color=red&#038;controls=1&#038;disablekb=0&#038;\" class=\"__youtube_prefs__  no-lazyload\" title=\"YouTube player\"  data-epytgalleryid=\"epyt_gallery_87445\"  allow=\"fullscreen; accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen data-no-lazy=\"1\" data-skipgform_ajax_framebjll=\"\"><\/iframe><div class=\"epyt-gallery-list\"><div>Sorry, there was a YouTube error.<\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>Running CLI java -jar jenkins-cli.jar [-s JENKINS_URL] command [options&#8230;] [arguments&#8230;] 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&#8230; <\/p>\n","protected":false},"author":1,"featured_media":3748,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_joinchat":[],"footnotes":""},"categories":[42],"tags":[2308,829,824,145,2306,2309,2312,2311,2310,826,2307],"class_list":["post-346","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-jenkins","tag-about-jenkins-cli","tag-cli","tag-command-line","tag-jenkins","tag-jenkins-cli","tag-jenkins-cli-guide","tag-jenkins-cli-instructions","tag-jenkins-cli-reference","tag-jenkins-cli-tutorial","tag-jenkins-command-line","tag-understand-jenkins-cli"],"_links":{"self":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/346","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/comments?post=346"}],"version-history":[{"count":2,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/346\/revisions"}],"predecessor-version":[{"id":25848,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/posts\/346\/revisions\/25848"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media\/3748"}],"wp:attachment":[{"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/media?parent=346"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/categories?post=346"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopsschool.com\/blog\/wp-json\/wp\/v2\/tags?post=346"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}