Java.io.IOException: No X-Jenkins-CLI2-Port (jenkins cli not working)

I am trying to run the following command:

java -jar jenkins-cli.jar -s http://jenkins_URL/ --username myusername --password mypassword help

But I get an error message:

java.io.IOException: none X-Jenkins-CLI2-Port among [null, X-Required-Permission, X-Jenkins, X-You-Are-In-Group, X-Hudson, Content-Length, Expires, X- You-Are-Authenticated-As, X-Permission-Implied-By, Set-Cookie, Server, X-Content-Type-Options, Date, X-Jenkins-Session, Content-Type] at hudson.cli.CLI.getCliTcpPort (CLI.java:284) at hudson.cli.CLI. (CLI.java:128) at hudson.cli.CLIConnectionFactory.connect (CLIConnectionFactory.java:72) at hudson.cli.CLI._main (CLI.java:473) on hudson.cli.CLI.main (CLI.java: 384) Suppressed: java.io.IOException: server responded to HTTP response code: 403 for URL: http://52.9.217.252:8888/cli at sun.net.www.protocol.http.HttpURLConnection.getInputStream (HttpURLConnection.java : 1628) on hudson.cli.FullDuplexHttpStream. (FullDuplexHttpStream.java:78) at hudson.cli.CLI.connectViaHttp (CLI.java:152) at hudson.cli.CLI. (CLI.java:132) ... 3 more

my config.xml file

 <?xml version='1.0' encoding='UTF-8'?> <hudson> <disabledAdministrativeMonitors/> <version>1.0</version> <numExecutors>2</numExecutors> <mode>NORMAL</mode> <useSecurity>true</useSecurity> <authorizationStrategy class="hudson.security.FullControlOnceLoggedInAuthorizationStrategy"> <denyAnonymousReadAccess>false</denyAnonymousReadAccess> </authorizationStrategy> <securityRealm class="hudson.security.HudsonPrivateSecurityRealm"> <disableSignup>true</disableSignup> <enableCaptcha>false</enableCaptcha> </securityRealm> <disableRememberMe>false</disableRememberMe> <projectNamingStrategy class="jenkins.model.ProjectNamingStrategy$DefaultProjectNamingStrategy"/> <workspaceDir>${ITEM_ROOTDIR}/workspace</workspaceDir> <buildsDir>${ITEM_ROOTDIR}/builds</buildsDir> <jdks/> <viewsTabBar class="hudson.views.DefaultViewsTabBar"/> <myViewsTabBar class="hudson.views.DefaultMyViewsTabBar"/> <clouds/> <scmCheckoutRetryCount>0</scmCheckoutRetryCount> <views> <hudson.model.AllView> <owner class="hudson" reference="../../.."/> <name>All</name> <filterExecutors>false</filterExecutors> <filterQueue>false</filterQueue> <properties class="hudson.model.View$PropertyList"/> </hudson.model.AllView> </views> <primaryView>All</primaryView> <slaveAgentPort>-1</slaveAgentPort> <label></label> <crumbIssuer class="hudson.security.csrf.DefaultCrumbIssuer"> <excludeClientIPFromCrumb>false</excludeClientIPFromCrumb> </crumbIssuer> <nodeProperties/> <globalNodeProperties/> </hudson> 
+6
source share
4 answers

There is an official solution on the Jenkins Wiki page for the CLI .

decision

  • Go to Jenkins Management (in the Jenkins interface)
  • Global Security Configuration
  • → "TCP port for JNLP agents": select fixed or random
+5
source

To verify that this is not a username and / or password error, change this line:

 <denyAnonymousReadAccess>true</denyAnonymousReadAccess> 

in

 <denyAnonymousReadAccess>false</denyAnonymousReadAccess> 

in the config.xml file.

Now you can connect to your jenkins interface to debug your credentials

Do not forget to reset it to true.

+1
source

For those who are watching how to do this work programmatically (unattended). You have to change

  <jenkins.CLI> <enabled>false</enabled> </jenkins.CLI> 

to

  <jenkins.CLI> <enabled>true</enabled> </jenkins.CLI> 

in / var / lib / jenkins / jenkins.CLI.xml and restart jenkins

+1
source

If you do not understand why this fails, run a debugger in strace / dtruss , for example.

 $ strace -fs1000 -e trace=network java -jar jenkins-cli.jar -s http://localhost:8080/ help 

If you have:

HTTP / 1.1 403 There was no doubt about the request.

then you need to either provide the crumb in the request or disable CSRF Protection .

Using the Jenkins CLI it still does not work when the rabbit agent is on, so you can use curl . For example (replace localhost with your Jenkins address):

  • Pay attention to the user API token ( /user/USER/configure ).
  • Get your baby:

     CRUMB=$(curl -s 'http://USER: TOKEN@localhost :8080/crumbIssuer/api/xml?xpath=concat(//crumbRequestField,":",//crumb)') 
  • Calling some command (for example, a list of tasks):

     curl -H $CRUMB http://USER: TOKEN@localhost :8080/api/json 

Related: Jenkins REST API Create Job

0
source

All Articles