簡體   English   中英

如何從命令行運行 Jenkins 構建?

[英]How to run a Jenkins Build from Command Line?

在為其內置命令行界面下載 jenkins jenkins-cli.jar 文件后,我在網上找到的教程提示我在命令提示符下執行以下命令以運行它:

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

但是當我輸入這個命令時,返回以下錯誤:

錯誤:無法訪問 jarfile jenkins-cli.jar

我不知道為什么會返回這個。 它可以使用Windows機器與我連接嗎? 為什么會發生這種情況,它最終如何運行?

https://jenkins.io/doc/book/managing/cli/參考HTTP連接方式
身份驗證最好使用 -auth 選項,該選項采用 username:apitoken 參數。 從 /me/configure 獲取您的 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,請確保它不會緩沖請求或響應主體。

此消息僅表示 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.

在這種情況下,它(我認為)與連接本身無關,但與 jar 文件位於同一文件夾中。

如果它無法訪問 jar 文件,則您在執行java -jar ...命令時可能與 jar 文件不在同一目錄中。

啟動終端並將 Director ( cd <folder> ) 更改為您下載 jar 文件的位置,然后重試。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM