2017-07-03 75 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.