Jenkins supports ssh authentication in CLI.
Below is a command to verify that I am authenticated:
java -jar jenkins-cli.jar -s http://myserver/jenkins who-am-i
Authenticated as: myuser Authorities: authenticated
However you still would meet permission error when running groovy script in CLI.
java -jar jenkins-cli.jar -s http://myserver/jenkins groovysh ‘jenkins.model.Jenkins.instance.pluginManager.plugins.each { println(“${it.longName} - ${it.version}”) };’
Exception in thread “main” java.lang.reflect.UndeclaredThrowableException at $Proxy2.main(Unknown Source) at hudson.cli.CLI.execute(CLI.java:271) at hudson.cli.CLI._main(CLI.java:417) at hudson.cli.CLI.main(CLI.java:322)
It’s a bug of Jenkins. The workaround is create a groovy script, then run that script via Jenkins CLI.
java -jar jenkins-cli.jar -s http://myserver/jenkins/ groovy test_script.gsh