<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Jenkins Command line Guide Archives - scmGalaxy</title>
	<atom:link href="https://www.scmgalaxy.com/tutorials/tag/jenkins-command-line-guide/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.scmgalaxy.com/tutorials/tag/jenkins-command-line-guide/</link>
	<description>A Platform for Software Engineers</description>
	<lastBuildDate>Sat, 27 Feb 2021 09:51:14 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1</generator>
	<item>
		<title>Complete guide to use Jenkins CLI / Command line &#124; Jenkins Tutorials</title>
		<link>https://www.scmgalaxy.com/tutorials/complete-guide-to-use-jenkins-cli-command-line/</link>
					<comments>https://www.scmgalaxy.com/tutorials/complete-guide-to-use-jenkins-cli-command-line/#comments</comments>
		
		<dc:creator><![CDATA[scmgalaxy K]]></dc:creator>
		<pubDate>Sun, 08 Jan 2017 08:37:19 +0000</pubDate>
				<category><![CDATA[Jenkins]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[CLI]]></category>
		<category><![CDATA[CLI / Command line]]></category>
		<category><![CDATA[Command line]]></category>
		<category><![CDATA[Jenkins CLI / Command line]]></category>
		<category><![CDATA[Jenkins Command line]]></category>
		<category><![CDATA[Jenkins Command line Guide]]></category>
		<category><![CDATA[Jenkins Command line Tutorials]]></category>
		<category><![CDATA[Jenkins Tutorials]]></category>
		<guid isPermaLink="false">http://www.scmgalaxy.com/tutorials/2017/01/08/complete-guide-to-use-jenkins-cli-command-line/</guid>

					<description><![CDATA[<p>Complete guide to use Jenkins CLI / Command line? Run Jenkins build from command is very simple in Linux system. [&#8230;]</p>
<p>The post <a href="https://www.scmgalaxy.com/tutorials/complete-guide-to-use-jenkins-cli-command-line/">Complete guide to use Jenkins CLI / Command line | Jenkins Tutorials</a> appeared first on <a href="https://www.scmgalaxy.com/tutorials">scmGalaxy</a>.</p>
]]></description>
										<content:encoded><![CDATA[<div><img fetchpriority="high" decoding="async" class="size-full wp-image-2959 aligncenter" src="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2017/01/complete-guide-to-use-jenki.png" alt="jenkins-cli-command-line" width="600" height="400" srcset="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2017/01/complete-guide-to-use-jenki.png 600w, https://www.scmgalaxy.com/tutorials/wp-content/uploads/2017/01/complete-guide-to-use-jenki-300x200.png 300w" sizes="(max-width: 600px) 100vw, 600px" /></div>
<div>Complete guide to use Jenkins CLI / Command line?</div>
<div></div>
<div>Run Jenkins build from command is very simple in Linux system. If you are using using windows, gitbash is a recommended which has bash shell in built. You can use windows command line as well. Jenkins has support to command line client that allows you to access Jenkins from command line.</div>
<div></div>
<div><strong>To Trigger Jenkins build from command line some prerequisite are there</strong></div>
<div></div>
<div>Jenkins service is running.</div>
<div>Enable security option under “Configure Global Security”</div>
<div></div>
<div>Go to jenkins dashboard in Home page ( e.g http://localhost:8080/ ) -&gt; Manage Jenkins</div>
<div>-&gt; Configure Global Security -&gt; Click on “Enable security” checkbox</div>
<div></div>
<div>
<p>You can also configure “Access Control” and “Authorization” option in Global Security page.</p>
<div><strong>Download Jenkins-cli.jar</strong></div>
<div>Download Jenkins-cli.jar from http://&lt;your_jenkins_server_url&gt;/jnlpJars/jenkins-cli.jar. (Here &lt;your_jenkins_server_url&gt; is your respective Jenkins server URL (development or staging))</div>
<div>Go to http://&lt;your_jenkins_server_url&gt;/cli and build your command by following the instructions there.</div>
</div>
<div></div>
<div><strong>How to login to Jenkins using commands</strong></div>
<div>If your Jenkins requires authentication, use &#8211;username and &#8211;password or &#8211;password-file options to specify the credentials. To avoid doing this for every command, you can also use the login CLI command once (with the same credentials parameters), and after that you may use other commands without specifying credentials.</div>
<div></div>
<div>Whenever the CLI tries to to connect to the Jenkins server, it offers the before mentioned SSH keys. When the user has those keys but don&#8217;t want use them to authenticate, preventing being prompted by the key&#8217;s password, it&#8217;s possible to use the -noKeyAuth argument. This way the CLI will never try to use the SSH keys available. failure to authenticate by itself does not constitute a fatal error. It will instead try to execute the command anyway, as the anonymous user.</div>
<div></div>
<div></div>
<div><strong>Login Jenkins using username and Password</strong></div>
<div>Jenkins allow us to trigger Jenkins build with any specific user, For that we have to pass username and password in command line.</div>
<div>$ java -jar &#8220;/tmp/kitchen/cache/jenkins-cli.jar&#8221; -s http://localhost:8080 who-am-i &#8211;username jenkins &#8211;password foobar</div>
<div>$ java -jar jenkins-cli.jar -s http://myjenkins help &#8211;username me &#8211;password mypassword</div>
<div></div>
<div><strong>Login Jenkins using public keys</strong></div>
<div>Starting 1.419 (which will be out July 4th), Jenkins CLI supports authentication based on the SSH key pair. Just like CloudBees DEV@cloud (or GitHub, or other similar sites), you interactively login from the web UI, then associate your public keys with your user account. Then CLI will silently authenticates itself using your ~/.ssh/id_rsa, ~/.ssh/id_dsa, or ~/.ssh/identity.</div>
<div>https://help.github.com/articles/generating-an-ssh-key/</div>
<div></div>
<div><strong>Login Jenkins using private keys</strong></div>
<div>You can also pass the priate key as follows</div>
<div>To use the -i option the syntax is as follows:</div>
<div>$ java -jar jenkins-cli.jar -s http://myjenkins help -i ~/.ssh/id_rsa</div>
<div>$ java -jar jenkins-cli.jar [-s JENKINS_URL] [-i PRIVATE_KEY] command [options&#8230;] [arguments&#8230;]</div>
<div>For compatibility reasons, unless you use the -i option,</div>
<div></div>
<div><strong>Login Jenkins using initialAdminPassword</strong></div>
<div>try user &#8220;admin&#8221; and password from &#8220;Jenkins\secrets\initialAdminPassword&#8221;</div>
<div>java -jar jenkins-cli.jar -s http://localhost:8080 who-am-i &#8211;username admin &#8211;password fe3f1e1624ea4be8873b7a35e28b24be</div>
<div></div>
<div><strong>Login Jenkins using passphrase</strong></div>
<div>Go to http://jenkins-serer:8085/user/admin/configure and set the passphrase in &#8220;SSH Public Keys&#8221; and use the same passphrase with jenkins commands.</div>
<div></div>
<div><strong>E.g 1 &#8211; Getting help</strong></div>
<div>The list of the available commands depends on the server you are talking to. Visit https://jenkins.example.com/cli or use &#8216;help&#8217; command to list them all:</div>
<div>&gt; java -jar jenkins-cli.jar -s https://jenkins.example.com help [command]</div>
<div></div>
<div><strong>E.g 2 &#8211; Run Jenkins Build From Command Line</strong></div>
<div>&gt; java -jar jenkins-cli.jar -s http://&lt;jenkins server&gt;/ build build-name [-c] [-f] [-p] [-r N] [-s] [-v] [-w]</div>
<div></div>
<div>build-name : Name of the job to build</div>
<div>-c  : Check for SCM changes before starting the build, and if there&#8217;s no change, exit without doing a build</div>
<div>-f  : Follow the build progress. Like -s only interrupts are not passed through to the build.</div>
<div>-p  : Specify the build parameters in the key=value format.</div>
<div>-s  : Wait until the completion/abortion of the command. Interrupts are passed through to the build.</div>
<div>-v  : Prints out the console output of the build. Use with -s</div>
<div>-w  : Wait until the start of the command</div>
<div></div>
<div>Example  &#8211; java -jar jenkins-cli.jar -s http://localhost:8080/ build &#8216;my-project-build&#8217; &#8211;username roop &#8211;password roop</div>
<div></div>
<div><strong>E.g 3 &#8211; List all jobs under the view: tools</strong></div>
<div>$ java -jar jenkins-cli.jar -s http://jenkins/ list-jobs tools</div>
<div></div>
<div><strong>E.g 4 &#8211; Get the configuration of the job: template</strong></div>
<div>$ java -jar jenkins-cli.jar -s http://jenkins/ get-job template &gt; template.xml</div>
<div></div>
<div><strong>E.g 5 &#8211; Create a new job based on the configuration</strong></div>
<div>$ java -jar jenkins-cli.jar -s http://jenkins/ create-job new_job_name &lt; new_job_name.xml</div>
<div></div>
<div><strong>E.g 6 &#8211; Run groovy script</strong></div>
<div>$ java -jar jenkins-cli.jar -s http://jenkins/ groovy scripts/add_job_to_view.groovy</div>
<div>If there are any parameters in the script, just as:</div>
<div>import jenkins.model.*</div>
<div></div>
<div>if (args.length != 2 ) {</div>
<div>  println &#8220;Error on arguments!&#8221;</div>
<div>}</div>
<div>def jobName  = args[0] ?: &#8216;a_job&#8217;</div>
<div>def viewName = args[1] ?: &#8216;a_view&#8217;</div>
<div></div>
<div>println jobName + &#8216; &#8216; + viewName</div>
<div></div>
<div>def v = Jenkins.instance.getView(viewName)</div>
<div>def i = Jenkins.instance.getItemByFullName(jobName)</div>
<div>if (v &amp;&amp; i) {</div>
<div>  v.add(i)</div>
<div>}</div>
<div></div>
<div>pass the parameters as:</div>
<div></div>
<div>$ java -jar jenkins-cli.jar -s http://jenkins/ groovy scripts/add_job_to_view.groovy JOB_NAME VIEM_NAME</div>
<div></div>
<div><strong>E.g 7 &#8211; Build a job</strong></div>
<div>$ java -jar jenkins-cli.jar -s http://jenkins/ build new_job_name</div>
<div></div>
<div><strong>E.g 8 &#8211; Diable a job</strong></div>
<div>$ java -jar jenkins-cli.jar -s http://jenkins/ disable-job new_job_name</div>
<div></div>
<div><strong>E.g 8 &#8211; Passing parameters when triggering a job build</strong></div>
<div>Job parameters are a very handy concept. Perhaps you&#8217;ve only ever used Jenkins or another CI system to automatically run builds when a remote SCM/git repo changes. You can also trigger builds manually from within Jenkins. And whilst you&#8217;re doing that, your job can prompt for parameters to the build.</div>
<div></div>
<div>For example, we have a job named similar to &#8220;Deploy XYZ App&#8221;. It has the git repo hardcoded in the job like a normal build, but when you press &#8220;Build&#8221;, it shows a list of options: string fields, drop-down lists, etc.</div>
<div></div>
<div>When the job runs, you can use these values anywhere within your job&#8217;s configuration. Its very cool.</div>
<div></div>
<div>But how to pass those same parameters via the CLI? You use the -p key=value flag for each parameter you want to pass.</div>
<div></div>
<div>So our finished product might look like:</div>
<div>$ 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</div>
<div></div>
<div><strong>Commons problems</strong></div>
<div>Operation timed out</div>
<div>$ java -jar jenkins-cli.jar -s YOUR_SERVER_URL help</div>
<div>Exception in thread &#8220;main&#8221; java.net.ConnectException: Operation timed out</div>
<div>at java.net.PlainSocketImpl.socketConnect(Native Method)</div>
<div>at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)</div>
<div>at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)</div>
<div>at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)</div>
<div>at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:432)</div>
<div>at java.net.Socket.connect(Socket.java:529)</div>
<div>at java.net.Socket.connect(Socket.java:478)</div>
<div>at java.net.Socket.&lt;init&gt;(Socket.java:375)</div>
<div>at java.net.Socket.&lt;init&gt;(Socket.java:189)</div>
<div>at hudson.cli.CLI.&lt;init&gt;(CLI.java:97)</div>
<div>at hudson.cli.CLI.&lt;init&gt;(CLI.java:82)</div>
<div>at hudson.cli.CLI._main(CLI.java:250)</div>
<div>at hudson.cli.CLI.main(CLI.java:199)</div>
<div>Check that the JNLP port is opened if you are using a firewall on your server. You can configure its value in Jenkins configuration. By default it is set to use a random port.</div>
<div></div>
<div>java.io.IOException: No X-Jenkins-CLI2-Port</div>
<div>java.io.IOException: No X-Jenkins-CLI2-Port among [X-Jenkins, null, Server, X-Content-Type-Options, Connection, X-You-Are-In-Group, X-Hudson, X-Permission-Implied-By, Date, X-Jenkins-Session, X-You-Are-Authenticated-As, X-Required-Permission, Set-Cookie, Expires, Content-Length, Content-Type]</div>
<div>at hudson.cli.CLI.getCliTcpPort(CLI.java:284)</div>
<div>at hudson.cli.CLI.&lt;init&gt;(CLI.java:128)</div>
<div>at hudson.cli.CLIConnectionFactory.connect(CLIConnectionFactory.java:72)</div>
<div>at hudson.cli.CLI._main(CLI.java:473)</div>
<div>at hudson.cli.CLI.main(CLI.java:384)</div>
<div>Suppressed: java.io.IOException: Server returned HTTP response code: 403 for URL: <a href="http://citest.gce.px/cli" target="_blank" rel="noopener">http://citest.gce.px/cli</a></div>
<div>at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1840)</div>
<div>at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1441)</div>
<div>at hudson.cli.FullDuplexHttpStream.&lt;init&gt;(FullDuplexHttpStream.java:78)</div>
<div>at hudson.cli.CLI.connectViaHttp(CLI.java:152)</div>
<div>at hudson.cli.CLI.&lt;init&gt;(CLI.java:132)</div>
<div>&#8230; 3 more</div>
<div>Solution: Go to Manage Jenkins -&gt; Configure Global Security -&gt; &#8220;TCP port for JNLP agents&#8221;: choose fixed or random</div>
<div></div>
<div><strong>Reference</strong></div>
<div><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></div>
<div><a href="http://lifuzu.com/blog/2014/04/24/playing-with-jenkins-create-job/" target="_blank" rel="noopener">http://lifuzu.com/blog/2014/04/24/playing-with-jenkins-create-job/</a></div>
<p>The post <a href="https://www.scmgalaxy.com/tutorials/complete-guide-to-use-jenkins-cli-command-line/">Complete guide to use Jenkins CLI / Command line | Jenkins Tutorials</a> appeared first on <a href="https://www.scmgalaxy.com/tutorials">scmGalaxy</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.scmgalaxy.com/tutorials/complete-guide-to-use-jenkins-cli-command-line/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
		<item>
		<title>Jenkins Command line Reference for login and trigger a job</title>
		<link>https://www.scmgalaxy.com/tutorials/jenkins-command-line-reference-for-login-and-trigger-a-job/</link>
					<comments>https://www.scmgalaxy.com/tutorials/jenkins-command-line-reference-for-login-and-trigger-a-job/#comments</comments>
		
		<dc:creator><![CDATA[scmgalaxy K]]></dc:creator>
		<pubDate>Thu, 05 Feb 2015 00:00:00 +0000</pubDate>
				<category><![CDATA[Jenkins]]></category>
		<category><![CDATA[Command line]]></category>
		<category><![CDATA[How]]></category>
		<category><![CDATA[How to login in Jenkins]]></category>
		<category><![CDATA[How to trigger a job in Jenkins]]></category>
		<category><![CDATA[Jenkins Command line]]></category>
		<category><![CDATA[Jenkins Command line Guide]]></category>
		<category><![CDATA[Jenkins Command line Reference]]></category>
		<category><![CDATA[Jenkins Command line Tutorial]]></category>
		<category><![CDATA[job]]></category>
		<category><![CDATA[Login]]></category>
		<category><![CDATA[Login Jenkins]]></category>
		<category><![CDATA[Process]]></category>
		<category><![CDATA[Reference]]></category>
		<category><![CDATA[Steps]]></category>
		<category><![CDATA[Trigger]]></category>
		<category><![CDATA[Ways]]></category>
		<guid isPermaLink="false">http://www.scmgalaxy.com/tutorials/2015/02/05/jenkins-command-line-reference-for-login-and-trigger-a-job/</guid>

					<description><![CDATA[<p>Grep will return 0 while the build is running: $ curl http://myjenkins/job/myjob/lastBuild/api/json &#124; grep &#8211;color result\&#8221;:null $ echo $? Trigger [&#8230;]</p>
<p>The post <a href="https://www.scmgalaxy.com/tutorials/jenkins-command-line-reference-for-login-and-trigger-a-job/">Jenkins Command line Reference for login and trigger a job</a> appeared first on <a href="https://www.scmgalaxy.com/tutorials">scmGalaxy</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><img decoding="async" class="alignnone size-full wp-image-3535 aligncenter" src="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2015/02/jenkins-command-line-refere.png" alt="jenkins-command-line-reference" width="600" height="400" srcset="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2015/02/jenkins-command-line-refere.png 600w, https://www.scmgalaxy.com/tutorials/wp-content/uploads/2015/02/jenkins-command-line-refere-300x200.png 300w" sizes="(max-width: 600px) 100vw, 600px" /></p>
<p><b>Grep will return 0 while the build is running:</b></p>
<p>$ curl http://myjenkins/job/myjob/lastBuild/api/json | grep &#8211;color result\&#8221;:null</p>
<p>$ echo $?</p>
<p><strong>Trigger a Jenkins Job from command line</strong></p>
<p>$ wget http://yourserver/job/MyJobname/build?delay=0sec</p>
<p>$ wget -O &#8211; $HUDSON_URL/job/JOBNAME/build</p>
<p><strong>Trigger a Jenkins Job without authentication</strong></p>
<p>$ curl http://jenkins:8080/job/my%20job/build</p>
<p><strong>Trigger a Jenkins Job with authentication</strong></p>
<p>$ curl &#8211;user dbacher:$MY_API_TOKEN http://jenkins:8080/job/my%20job/build</p>
<p>$ curl &#8211;user &lt;your_jenkins_username&gt;:&lt;your_jenkins_API_key&gt; http://&lt;jenkins_server_url&gt;/job/&lt;your_jenkins_job_name&gt;/build</p>
<p><strong>Running commands against a secure Jenkins (basic auth or ssh keys)</strong></p>
<p>$ java -jar jenkins-cli.jar -s http://myjenkins help &#8211;username me &#8211;password mypassword</p>
<p>$ java -jar jenkins-cli.jar -s http://myjenkins help -i ~/.ssh/id_rsa</p>
<p><strong>Triggering a job build against a secure Jenkins (avoiding a 1.5 year old open bug!)</strong></p>
<p>$ java -jar jenkins-cli.jar -s http://myjenkins build &#8216;My Awesome Jenkins Job&#8217; -i ~/.ssh/id_rsa</p>
<p>$ java -jar jenkins-cli.jar -s http://myjenkins build &#8216;My Awesome Jenkins Job&#8217; -i ~/.ssh/id_rsa -s -v</p>
<p><strong>Passing parameters when triggering a job build</strong></p>
<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>
<p><strong>Reference</strong></p>
<p><a href="http://starkandwayne.com/articles/2013/04/12/jenkins-builds-from-cli/" target="_blank" rel="noopener">http://starkandwayne.com/articles/2013/04/12/jenkins-builds-from-cli/</a></p>
<p><a href="http://www.scmgalaxy.com/index.php?option=com_k2&amp;view=item&amp;id=890:ways-to-login-jenkins-using-command-line&amp;Itemid=120" target="_blank" rel="noopener">http://www.scmgalaxy.com/index.php?option=com_k2&amp;view=item&amp;id=890:ways-to-login-jenkins-using-command-line&amp;Itemid=120</a></p>
<p><strong>Appendix</strong></p>
<p>1. How to get your_jenkins_API_key?</p>
<ul>
<li>Login to your Jenkins.</li>
<li>Click on the username in the top right.</li>
<li>Click on Configure.</li>
<li>Click on ‘Show API Token’ button.</li>
<li>You got it.</li>
</ul>
<p>The post <a href="https://www.scmgalaxy.com/tutorials/jenkins-command-line-reference-for-login-and-trigger-a-job/">Jenkins Command line Reference for login and trigger a job</a> appeared first on <a href="https://www.scmgalaxy.com/tutorials">scmGalaxy</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.scmgalaxy.com/tutorials/jenkins-command-line-reference-for-login-and-trigger-a-job/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
	</channel>
</rss>
