2017-07-03 78 views
0

在下载jenkins jenkins-cli.jar文件以获取其内置命令行界面后,我收到我在线发现的教程的提示,以便在命令提示符处执行以下命令以运行它:如何从命令行运行Jenkins构建?

java -jar jenkins-cli.jar -s http://localhost:8080/ help 

但是,当我输入这个命令,将返回以下错误:

Error: Unable to access jarfile jenkins-cli.jar

我不知道为什么会被返回。它可以使用Windows机器与我连接吗?任何提示为什么发生这种情况,以及它如何最终可能会运行,将不胜感激。提前致谢!

回答

0

https://jenkins.io/doc/book/managing/cli/参阅HTTP连接模式
认证是优选与-auth选项,这需要一个用户名:apitoken参数。获得从/我你的API令牌/配置:

**java -jar jenkins-cli.jar [-s JENKINS_URL] -auth kohsuke:abc1234ffe4a command ...** 

(实际密码也被接受,但是这是气馁。)

您也可以先于论证与@从文件加载相同的内容:

java -jar jenkins-cli.jar [-s JENKINS_URL] -auth @/home/kohsuke/.jenkins-cli command ... 通常不需要进行特殊的系统配置来启用基于HTTP的CLI连接。如果您在HTTP(S)反向代理的后面运行Jenkins,请确保它不缓冲请求或响应主体。

+0

运行它现在下面你分享的链接上的说明后,我仍然得到了同样的问题。我无法访问jar文件jenkins-cli.jar –

0

此消息仅表示jenkins-cli.jar不在您的$ PATH或您运行java的相同目录中。

这里,jenkins-cli.jar文件位于我的$ HOME/bin目录中。起初,我尝试从我的$ HOME

➜ ~ java -jar jenkins-cli.jar                        
Error: Unable to access jarfile jenkins-cli.jar 

从$ HOME/bin中

➜ ~ cd bin 
➜ ~/bin ls -al jenkins-cli.jar  
-rw-rw-r-- 1 user user 2849829 juin 23 10:04 jenkins-cli.jar 
➜ ~/bin java -jar jenkins-cli.jar 
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) 
-http  : use a plain CLI protocol over HTTP(S) (the default; mutually exclusive with -ssh and -remoting) 
-ssh   : use SSH protocol (requires -user; SSH port must be open on server, and user must have registered a public key) 
-remoting : use deprecated Remoting channel protocol (if enabled on server; for compatibility with legacy commands or command modes only) 
-i KEY  : SSH private key file used for authentication (for use with -ssh or -remoting) 
-p HOST:PORT : HTTP proxy host and port for HTTPS proxy tunneling. See https://jenkins.io/redirect/cli-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 
-user  : specify user (for use with -ssh) 
-strictHostKey : request strict host key checking (for use with -ssh) 
-logger FINE : enable detailed logging from the client 
-auth [ USER:SECRET | @FILE ] : specify username and either password or API token (or load from them both from a file); 
for use with -http, or -remoting but only when the JNLP agent port is disabled 

The available commands depend on the server. Run the help command to 
see the list.