假設Jenkins的URL爲http://22.11.140.38:9080/jenkins/
基本的格式爲
java -jar jenkins-cli.jar [-s JENKINS_URL] command[options][args] |
下面具體介紹各個命令的作用及基本使用方法
1. help 查看所有內嵌命令的基本功能 無參數
Eg. java -jar jenkins-cli.jar -shttp://22.11.140.38:9080/jenkins/ help |
2. build 執行一次構建
參數說明: JOB : Name of the job to build 要構建的job名稱 -c : Check for SCM changes before starting the build, andif there's no change, exit without doing a build -p : Specify the build parameters in the key=value format. -rVAL : Number of times to retry reading of the output log ifit does not exists on first attempt. Defaults to 0. Use with -v. -s : Wait until the completion/abortion of the command -v : Prints out the console output of the build. Use with-s -w : Wait until the start of the command --usernameVAL : User name to authenticate yourself to Jenkins --passwordVAL : Password for authentication. Note that passing a passwordin arguments is insecure. --password-file VAL : File that contains the password |
3. cancel-quiet-down: Cancel the effect of the "quiet-down"command.
4. clear-queue: Clears the build queue
5. connect-node: Reconnect to a node
6. console:Retrieves console output of a build 顯示某job某次構建的的控制檯輸出
參數說明: JOB : Name of the job BUILD : Build number or permalink to point to the build. Defaults to the last build -f : If the build is in progress, stay around and append console output as it comes, like 'tail -f' -nN : Display the last N lines --usernameVAL : User name to authenticate yourself to Jenkins --passwordVAL : Password for authentication. Note that passing a password in arguments is insecure. --password-file VAL : File that contains the password |
7. copy-job:Copies a job
參數說明: SRC : Name of the job to copy DST : Name of the new job to be created. --usernameVAL : User name to authenticate yourself to Jenkins --passwordVAL : Password for authentication. Note that passing a password in arguments is insecure. --password-file VAL : File that contains the password |
8. create-job: Creates a new job by reading stdin as aconfiguration XML file.
從一個XML文檔中創建一個job
Eg. java -jar/home/jboss/.jenkins/jenkins-cli.jar -shttp://22.11.140.61:9080/jenkins/ create-job testttt |
9. create-node: Creates a new node by reading stdin as a XMLconfiguration.
10. delete-builds: Deletes build record(s)
參數說明: JOB : Name of the job to build RANGE : Range of the build records to delete. 'N-M', 'N,M', or 'N' --usernameVAL : User name to authenticate yourself to Jenkins --passwordVAL : Password for authentication. Note that passing a passwordin arguments is insecure. --password-file VAL : File that contains thepassword Eg. java -jar/home/jboss/.jenkins/jenkins-cli.jar -shttp://22.11.140.61:9080/jenkins/ delete-builds3-5 |
11. delete-job
參數說明: NAME : Job name --usernameVAL : User name to authenticate yourself to Jenkins --passwordVAL : Password for authentication. Note that passing a password in arguments is insecure. --password-file VAL : File that contains the password |
12. delete-node Deletes a node
13. disable-job Disables a job 相當於“停止構建”
參數說明: NAME : Job name --usernameVAL : User name to authenticate yourself to Jenkins --passwordVAL : Password for authentication. Note that passing a passwordin arguments is insecure. --password-file VAL : File that contains the password |
14. disconnect-node Disconnects from a node
15. enable-job Enables a job 相當於恢復可構建狀態
參數說明: NAME : Job name --usernameVAL : User name to authenticate yourself to Jenkins --passwordVAL : Password for authentication. Note that passing a password in arguments is insecure. --password-file VAL : File that contains the password |
16. get-job Dumps the job definition XML to stdout 得到job定義的XML文檔
參數說明: JOB : Name of the job --usernameVAL : User name to authenticate yourself to Jenkins --passwordVAL : Password for authentication. Note that passing a password in arguments is insecure. --password-file VAL : File that contains the password |
17. get-node Dumps the node definition XML to stdout
18. groovy Executes the specified Groovy script.
19. groovysh Runs an interactive groovy shell.
20. help Lists all the available commands. 無參數
21. install-plugin Installs a plugin either from a file, an URL, or from updatecenter. 安裝插件
22. install-tool Performsautomatic tool installation, and print its location to stdout. Canbe only called from inside a build.
23. keep-build Mark the build to keep the build forever.
24. list-changes Dumps the changelog for thespecified build(s).輸出某一次或幾次構建的變更記錄
參數說明: JOB : Name of the job to build RANGE : Range of the build records to delete. 'N-M', 'N,M', or 'N' -format [XML | CSV | PLAIN] : Controls howthe output from this command is printed. --usernameVAL :User name to authenticate yourself to Jenkins --passwordVAL : Password for authentication. Note that passing a password in arguments is insecure. --password-fileVAL : File that contains the password |
25. list-jobs Lists all jobs in a specific view or item group.列出所有的jobs名稱,其後可以接視圖名稱,默認顯示全部
Eg. java -jar/home/jboss/.jenkins/jenkins-cli.jar -s http://22.11.140.61:9080/jenkins/ list-jobsviewname |
26. list-plugins Outputs a list of installedplugins. 列出安裝的所有插件
27. login Saves the current credential to allow future commands to runwithout explicit credential information.保存登錄狀態
參數說明: --usernameVAL : User name to authenticate yourself to Jenkins --passwordVAL : Password for authentication. Note that passing a password in arguments is insecure. --password-file VAL : File that contains the password |
28. logout Deletes the credential stored with the login command.註銷
29. mail Reads stdin and sends that out as an e-mail.
30. offline-node Stop using a node for performing builds temporarily, until the next"online-node" command.
31. online-node Resume using a node for performing builds, to cancelout the earlier "offline-node" command.
32. quiet-down Quiet down Jenkins, in preparationfor a restart. Don?. start any builds.
33. reload-configuration Discard all the loaded data in memory and reload everything fromfile system. Useful when you modified config files directly ondisk.重新加載配置文件無參數
34. restart Restart Jenkins 重啓Jenkins
35. safe-restart Safely restartJenkins 安全重啓Jenkins,即等待已有的構建完成再重啓
36. safe-shutdown Puts Jenkins into the quiet mode, wait for existing builds to becompleted, and then shut down Jenkins.安全關閉Jenkins
37. session-id Outputs the session ID, which changes every time Jenkinsrestarts
38. set-build-description Sets the description of a build.爲已有構建添加描述
參數說明: JOB : Name of the job to build BUILD# : Number of the build DESCRIPTION : Description to be set. '=' to read from stdin. --usernameVAL : User name to authenticate yourself to Jenkins --passwordVAL : Password for authentication. Note that passing a password in arguments is insecure. --password-file VAL : File that contains the password |
39. set-build-display-name Sets the displayName of a build重命名默認的構建編號
參數說明: JOB : Name of the job to build BUILD# : Number of the build DISPLAYNAME : DisplayName to be set. '-' to read from stdin. --usernameVAL : User name to authenticate yourself to Jenkins --passwordVAL : Password for authentication. Note that passing a password in arguments is insecure. --password-file VAL : File that contains the password |
40. set-build-parameter Update/set the buildparameter of the current build in progress
參數說明: NAME : Name of the build variable VALUE : Value of the build variable --usernameVAL : User name to authenticate yourself to Jenkins --passwordVAL : Password for authentication. Note that passing a password in arguments is insecure. --password-file VAL : File that contains the password |
41. set-build-result Sets the result of the current build. Works only if invoked fromwithin a build.
42. shutdown Immediatelyshuts down Jenkins server 立即關閉jenkins
43. update-job Updates the job definition XML from stdin. Theopposite of the get-job command
44. update-node Updates the node definition XML from stdin. The opposite of theget-node command
45. version Outputs the current version. 查看當前版本
46. wait-node-offline Wait for a node to become offline
47. wait-node-online Wait for a node to become online
48. who-am-i Reports your credential andpermissions 查看當前登錄用戶
Tips:爲了操作方便,建議先通過login命令保存登錄狀態,這樣就不需要每次執行操作都加上用戶名密碼參數了;缺點是安全性不好,記得操作結束之後logout