Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-38318

jenkins-cli.jar example clarity

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved (View Workflow)
    • Priority: Minor
    • Resolution: Not A Defect
    • Component/s: cli
    • Labels:
      None
    • Similar Issues:

      Description

      I am working through `https://wiki.jenkins-ci.org/display/JENKINS/Jenkins+CLI`.

      I am unable to get the jenkins-cli.jar to work, but am able to get ssh to work.

      ssh -i localjenkins -p 59319 admin@localhost list-plugins (works)
      

      versus

      java -jar ~/Downloads/jenkins-cli.jar -i localjenkins -s http://localhost:8080 (or 59319)
      

      While it seems you must supply a protocol (http) in the URI it is unclear to me if it uses it. I assume that the CLI runs off of the SSL port which is not the same (59319 not 8080) in my case. I suspect the issue is how do you 'pick' the user associated with the ssh keys, but I am unsure. Not sure if this is a bug, improvement, or user error; but some guidance would be appreciated.

      Regards.

      Ron

        Attachments

          Activity

          Hide
          ronald_petty Ronald Petty added a comment -

          curl -vL http://localhost:8080/cli (also creates the 403)

          This works:

          curl -vL --user admin:admin http://localhost:8080/cli

          Maybe I don't understand how the SSH keys work per user (as its not used in these examples)

          Show
          ronald_petty Ronald Petty added a comment - curl -vL http://localhost:8080/cli (also creates the 403) This works: curl -vL --user admin:admin http://localhost:8080/cli Maybe I don't understand how the SSH keys work per user (as its not used in these examples)
          Hide
          ronald_petty Ronald Petty added a comment - - edited

          JNLP is disabled by default in GUI, but it actually shows listening in jenkins.log (might be another issue.) I enabled on fixed port and now I can connect but it hangs.

          java -jar ~/Downloads/jenkins-cli.jar -i localjenkins -s https://localhost:6666 list-plugins

          INFO: Accepted connection #3 from /127.0.0.1:62116

          After boredom sets in, hit CTRL-C

          WARNING: Connection #4 failed
          java.io.EOFException
          at java.io.DataInputStream.readFully(DataInputStream.java:197)
          at java.io.DataInputStream.readUTF(DataInputStream.java:609)
          at java.io.DataInputStream.readUTF(DataInputStream.java:564)
          at hudson.TcpSlaveAgentListener$ConnectionHandler.run(TcpSlaveAgentListener.java:176)

          Headers per CURL

          curl -vL --user admin:admin http://localhost:8080/ > /dev/null
          ...
          < X-Hudson-CLI-Port: 6666
          < X-Jenkins-CLI-Port: 6666
          < X-Jenkins-CLI2-Port: 6666
          ...

          Show
          ronald_petty Ronald Petty added a comment - - edited JNLP is disabled by default in GUI, but it actually shows listening in jenkins.log (might be another issue.) I enabled on fixed port and now I can connect but it hangs. java -jar ~/Downloads/jenkins-cli.jar -i localjenkins -s https://localhost:6666 list-plugins INFO: Accepted connection #3 from /127.0.0.1:62116 After boredom sets in, hit CTRL-C WARNING: Connection #4 failed java.io.EOFException at java.io.DataInputStream.readFully(DataInputStream.java:197) at java.io.DataInputStream.readUTF(DataInputStream.java:609) at java.io.DataInputStream.readUTF(DataInputStream.java:564) at hudson.TcpSlaveAgentListener$ConnectionHandler.run(TcpSlaveAgentListener.java:176) Headers per CURL curl -vL --user admin:admin http://localhost:8080/ > /dev/null ... < X-Hudson-CLI-Port: 6666 < X-Jenkins-CLI-Port: 6666 < X-Jenkins-CLI2-Port: 6666 ...
          Hide
          ronald_petty Ronald Petty added a comment - - edited

          More madness, attempt different ways, get different guidance.

          laptop:temp ronaldpetty$ java -jar ~/Downloads/jenkins-cli.jar -s http://localhost:8080
          
          ERROR: You must authenticate to access this Jenkins.
          Use --username/--password/--password-file parameters or login command.
          
          laptop:temp ronaldpetty$ java -jar ~/Downloads/jenkins-cli.jar --username=admin --password=admin -s http://localhost:8080 list-plugins
          Neither -s nor the JENKINS_URL env var is specified.
          Jenkins CLI
          Usage: java -jar jenkins-cli.jar [-s URL] command [opts...] args...
          Options:
          -s URL       : the server URL (defaults to the JENKINS_URL env var)
          -i KEY       : SSH private key file used for authentication
          -p HOST:PORT : HTTP proxy host and port for HTTPS proxy tunneling. See http://jenkins-ci.org/https-proxy-tunnel
          -noCertificateCheck : bypass HTTPS certificate check entirely. Use with caution
          -noKeyAuth   : dont try to load the SSH authentication private key. Conflicts with -i
          
          The available commands depend on the server. Run the help command to
          see the list.
          
          laptop:temp ronaldpetty$ java -jar ~/Downloads/jenkins-cli.jar -s http://localhost:8080 login
          
          ERROR: No credentials specified.
          java -jar jenkins-cli.jar login [--username VAL] [--password VAL] [--password-file VAL]
          Saves the current credential to allow future commands to run without explicit credential information.
           --username VAL      : User name to authenticate yourself to Jenkins
           --password VAL      : Password for authentication. Note that passing a
                                 password in arguments is insecure.
           --password-file VAL : File that contains the password
          
          laptop:temp ronaldpetty$ java -jar ~/Downloads/jenkins-cli.jar --username=admin --password=admin -s http://localhost:8080 login
          Neither -s nor the JENKINS_URL env var is specified.
          Jenkins CLI
          Usage: java -jar jenkins-cli.jar [-s URL] command [opts...] args...
          Options:
          -s URL       : the server URL (defaults to the JENKINS_URL env var)
          -i KEY       : SSH private key file used for authentication
          -p HOST:PORT : HTTP proxy host and port for HTTPS proxy tunneling. See http://jenkins-ci.org/https-proxy-tunnel
          -noCertificateCheck : bypass HTTPS certificate check entirely. Use with caution
          -noKeyAuth   : dont try to load the SSH authentication private key. Conflicts with -i
          
          The available commands depend on the server. Run the help command to
          see the list.
          
          Show
          ronald_petty Ronald Petty added a comment - - edited More madness, attempt different ways, get different guidance. laptop:temp ronaldpetty$ java -jar ~/Downloads/jenkins-cli.jar -s http: //localhost:8080 ERROR: You must authenticate to access this Jenkins. Use --username/--password/--password-file parameters or login command. laptop:temp ronaldpetty$ java -jar ~/Downloads/jenkins-cli.jar --username=admin --password=admin -s http: //localhost:8080 list-plugins Neither -s nor the JENKINS_URL env var is specified. Jenkins CLI Usage: java -jar jenkins-cli.jar [-s URL] command [opts...] args... Options: -s URL : the server URL (defaults to the JENKINS_URL env var ) -i KEY : SSH private key file used for authentication -p HOST:PORT : HTTP proxy host and port for HTTPS proxy tunneling. See http: //jenkins-ci.org/https-proxy-tunnel -noCertificateCheck : bypass HTTPS certificate check entirely. Use with caution -noKeyAuth : dont try to load the SSH authentication private key. Conflicts with -i The available commands depend on the server. Run the help command to see the list. laptop:temp ronaldpetty$ java -jar ~/Downloads/jenkins-cli.jar -s http: //localhost:8080 login ERROR: No credentials specified. java -jar jenkins-cli.jar login [--username VAL] [--password VAL] [--password-file VAL] Saves the current credential to allow future commands to run without explicit credential information. --username VAL : User name to authenticate yourself to Jenkins --password VAL : Password for authentication. Note that passing a password in arguments is insecure. --password-file VAL : File that contains the password laptop:temp ronaldpetty$ java -jar ~/Downloads/jenkins-cli.jar --username=admin --password=admin -s http: //localhost:8080 login Neither -s nor the JENKINS_URL env var is specified. Jenkins CLI Usage: java -jar jenkins-cli.jar [-s URL] command [opts...] args... Options: -s URL : the server URL (defaults to the JENKINS_URL env var ) -i KEY : SSH private key file used for authentication -p HOST:PORT : HTTP proxy host and port for HTTPS proxy tunneling. See http: //jenkins-ci.org/https-proxy-tunnel -noCertificateCheck : bypass HTTPS certificate check entirely. Use with caution -noKeyAuth : dont try to load the SSH authentication private key. Conflicts with -i The available commands depend on the server. Run the help command to see the list.
          Hide
          ronald_petty Ronald Petty added a comment -

          More...

          laptop:temp ronaldpetty$ java -jar jenkins-cli.jar -s http://localhost:8080/ build random
          
          ERROR: No such job 'random'
          
          laptop:temp ronaldpetty$ java -jar jenkins-cli.jar -s http://localhost:8080/ help
          
          ERROR: You must authenticate to access this Jenkins.
          Use --username/--password/--password-file parameters or login command.
          
          laptop:temp ronaldpetty$ java -jar jenkins-cli.jar -s http://localhost:8080/ who-am-i
          
          ERROR: anonymous is missing the Overall/Read permission
          
          Show
          ronald_petty Ronald Petty added a comment - More... laptop:temp ronaldpetty$ java -jar jenkins-cli.jar -s http: //localhost:8080/ build random ERROR: No such job 'random' laptop:temp ronaldpetty$ java -jar jenkins-cli.jar -s http: //localhost:8080/ help ERROR: You must authenticate to access this Jenkins. Use --username/--password/--password-file parameters or login command. laptop:temp ronaldpetty$ java -jar jenkins-cli.jar -s http: //localhost:8080/ who-am-i ERROR: anonymous is missing the Overall/Read permission
          Hide
          ronald_petty Ronald Petty added a comment -

          Got one to work!

          laptop:temp ronaldpetty$ java -jar jenkins-cli.jar -i localjenkins -s http://localhost:8080/ who-am-i
          Authenticated as: admin
          Authorities:
            authenticated
          

          So maybe its the trailing 'slash' on the URI or the particular command.

          Show
          ronald_petty Ronald Petty added a comment - Got one to work! laptop:temp ronaldpetty$ java -jar jenkins-cli.jar -i localjenkins -s http: //localhost:8080/ who-am-i Authenticated as: admin Authorities: authenticated So maybe its the trailing 'slash' on the URI or the particular command.
          Hide
          ronald_petty Ronald Petty added a comment -

          Figured it out.

          "TCP port for JNLP agents"

          Needs to be enabled.

          So when using a newer version of Jenkins, if it is disabled, it looks like this.

          laptop:temp ronaldpetty$ java -jar ~/Downloads/jenkins-cli.jar -i localjenkins -s http://localhost:8080
          java.io.IOException: No X-Jenkins-CLI2-Port among [X-Jenkins, null, Server, X-Content-Type-Options, 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]
          	at hudson.cli.CLI.getCliTcpPort(CLI.java:284)
          	at hudson.cli.CLI.<init>(CLI.java:128)
          	at hudson.cli.CLIConnectionFactory.connect(CLIConnectionFactory.java:72)
          	at hudson.cli.CLI._main(CLI.java:473)
          	at hudson.cli.CLI.main(CLI.java:384)
          	Suppressed: java.io.IOException: Server returned HTTP response code: 403 for URL: http://localhost:8080/cli
          		at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1840)
          		at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1441)
          		at hudson.cli.FullDuplexHttpStream.<init>(FullDuplexHttpStream.java:78)
          		at hudson.cli.CLI.connectViaHttp(CLI.java:152)
          		at hudson.cli.CLI.<init>(CLI.java:132)
          		... 3 more
          

          When you enable (random, or fixed) it works.

          Sorry for the debugging session, but I think the docs could be a little clearer on what is required set up to use this.

          Show
          ronald_petty Ronald Petty added a comment - Figured it out. "TCP port for JNLP agents" Needs to be enabled. So when using a newer version of Jenkins, if it is disabled, it looks like this. laptop:temp ronaldpetty$ java -jar ~/Downloads/jenkins-cli.jar -i localjenkins -s http: //localhost:8080 java.io.IOException: No X-Jenkins-CLI2-Port among [X-Jenkins, null , Server, X-Content-Type-Options, 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] at hudson.cli.CLI.getCliTcpPort(CLI.java:284) at hudson.cli.CLI.<init>(CLI.java:128) at hudson.cli.CLIConnectionFactory.connect(CLIConnectionFactory.java:72) at hudson.cli.CLI._main(CLI.java:473) at hudson.cli.CLI.main(CLI.java:384) Suppressed: java.io.IOException: Server returned HTTP response code: 403 for URL: http: //localhost:8080/cli at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1840) at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1441) at hudson.cli.FullDuplexHttpStream.<init>(FullDuplexHttpStream.java:78) at hudson.cli.CLI.connectViaHttp(CLI.java:152) at hudson.cli.CLI.<init>(CLI.java:132) ... 3 more When you enable (random, or fixed) it works. Sorry for the debugging session, but I think the docs could be a little clearer on what is required set up to use this.
          Hide
          danielbeck Daniel Beck added a comment -

          JENKINS-18114 will be fixed in 2.24, so that shouldn't be a problem anymore.

          Show
          danielbeck Daniel Beck added a comment - JENKINS-18114 will be fixed in 2.24, so that shouldn't be a problem anymore.

            People

            • Assignee:
              Unassigned
              Reporter:
              ronald_petty Ronald Petty
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: