Jenkins 命令行操作说明文档
假设Jenkins的URL为http://22.11.140.38:9080/jenkins/
基本的格式为
java
基本的格式为
java-jarjenkins-cli.jar[-sJENKINS_URL]command[options][args]
下面具体介绍各个命令的作用及基本使用方法
1.help查看所有内嵌命令的基本功能无参数
Eg.
java-jarjenkins-cli.jar-shttp://22.11.140.38:9080/jenkins/help
2.build执行一次构建
参数说明:
JOB:Nameofthejobtobuild要构建的job名称
-c:CheckforSCMchangesbeforestartingthebuild,andif
there'snochange,exitwithoutdoingabuild
-p:Specifythebuildparametersinthekey=valueformat.
-rVAL:Numberoftimestoretryreadingoftheoutputlogifit
doesnotexistsonfirstattempt.Defaultsto0.Use
with-v.
-s:Waituntilthecompletion/abortionofthecommand
-v:Printsouttheconsoleoutputofthebuild.Usewith-s
-w:Waituntilthestartofthecommand
--usernameVAL:UsernametoauthenticateyourselftoJenkins
--passwordVAL:Passwordforauthentication.Notethatpassinga
passwordinargumentsisinsecure.
--password-fileVAL:Filethatcontainsthepassword
3.cancel-quiet-down:Canceltheeffectofthe"quiet-down"command.
4.clear-queue:Clearsthebuildqueue
5.connect-node:Reconnecttoanode
6.console:Retrievesconsoleoutputofabuild显示某job某次构建的的控制台输出
参数说明:
JOB:Nameofthejob
BUILD:Buildnumberorpermalinktopointtothebuild.
Defaultstothelastbuild
-f:Ifthebuildisinprogress,stayaroundandappend
consoleoutputasitcomes,like'tail-f'
-nN:DisplaythelastNlines
--usernameVAL:UsernametoauthenticateyourselftoJenkins
--passwordVAL:Passwordforauthentication.Notethatpassinga
passwordinargumentsisinsecure.
--password-fileVAL:Filethatcontainsthepassword
7.copy-job:Copiesajob
参数说明:
SRC:Nameofthejobtocopy
DST:Nameofthenewjobtobecreated.
--usernameVAL:UsernametoauthenticateyourselftoJenkins
--passwordVAL:Passwordforauthentication.Notethatpassinga
passwordinargumentsisinsecure.
--password-fileVAL:Filethatcontainsthepassword
8.create-job:CreatesanewjobbyreadingstdinasaconfigurationXMLfile.
从一个XML文档中创建一个job
Eg.
java-jar/home/jboss/.jenkins/jenkins-cli.jar-shttp://22.11.140.61:9080/jenkins/create-jobtestttt
9.create-node:CreatesanewnodebyreadingstdinasaXMLconfiguration.
10.delete-builds:Deletesbuildrecord(s)
参数说明:
JOB:Nameofthejobtobuild
RANGE:Rangeofthebuildrecordstodelete.'N-M','N,M',or
'N'
--usernameVAL:UsernametoauthenticateyourselftoJenkins
--passwordVAL:Passwordforauthentication.Notethatpassinga
passwordinargumentsisinsecure.
--password-fileVAL:Filethatcontainsthepassword
Eg.
java-jar/home/jboss/.jenkins/jenkins-cli.jar-shttp://22.11.140.61:9080/jenkins/delete-builds3-5
11.delete-job
参数说明:
NAME:Jobname
--usernameVAL:UsernametoauthenticateyourselftoJenkins
--passwordVAL:Passwordforauthentication.Notethatpassinga
passwordinargumentsisinsecure.
--password-fileVAL:Filethatcontainsthepassword
12.delete-nodeDeletesanode
13.disable-jobDisablesajob相当于“停止构建”
参数说明:
NAME:Jobname
--usernameVAL:UsernametoauthenticateyourselftoJenkins
--passwordVAL:Passwordforauthentication.Notethatpassinga
passwordinargumentsisinsecure.
--password-fileVAL:Filethatcontainsthepassword
14.disconnect-nodeDisconnectsfromanode
15.enable-jobEnablesajob相当于恢复可构建状态
参数说明:
NAME:Jobname
--usernameVAL:UsernametoauthenticateyourselftoJenkins
--passwordVAL:Passwordforauthentication.Notethatpassinga
passwordinargumentsisinsecure.
--password-fileVAL:Filethatcontainsthepassword
16.get-jobDumpsthejobdefinitionXMLtostdout得到job定义的XML文档
参数说明:
JOB:Nameofthejob
--usernameVAL:UsernametoauthenticateyourselftoJenkins
--passwordVAL:Passwordforauthentication.Notethatpassinga
passwordinargumentsisinsecure.
--password-fileVAL:Filethatcontainsthepassword
17.get-nodeDumpsthenodedefinitionXMLtostdout
18.groovyExecutesthespecifiedGroovyscript.
19.groovyshRunsaninteractivegroovyshell.
20.helpListsalltheavailablecommands.无参数
21.install-pluginInstallsaplugineitherfromafile,anURL,orfromupdatecenter.安装插件
22.install-toolPerformsautomatictoolinstallation,andprintitslocationtostdout.Canbeonlycalledfrominsideabuild.
23.keep-buildMarkthebuildtokeepthebuildforever.
24.list-changesDumpsthechangelogforthespecifiedbuild(s).输出某一次或几次构建的变更记录
参数说明:
JOB:Nameofthejobtobuild
RANGE:Rangeofthebuildrecordstodelete.'N-M',
'N,M',or'N'
-format[XML|CSV|PLAIN]:Controlshowtheoutputfromthiscommandis
printed.
--usernameVAL:UsernametoauthenticateyourselftoJenkins
--passwordVAL:Passwordforauthentication.Notethatpassinga
passwordinargumentsisinsecure.
--password-fileVAL:Filethatcontainsthepassword
25.list-jobsListsalljobsinaspecificvieworitemgroup.列出所有的jobs名称,其后可以接视图名称,默认显示全部
Eg.
java-jar/home/jboss/.jenkins/jenkins-cli.jar-shttp://22.11.140.61:9080/jenkins/list-jobsviewname
26.list-pluginsOutputsalistofinstalledplugins.列出安装的所有插件
27.loginSavesthecurrentcredentialtoallowfuturecommandstorunwithoutexplicitcredentialinformation.保存登录状态
参数说明:
--usernameVAL:UsernametoauthenticateyourselftoJenkins
--passwordVAL:Passwordforauthentication.Notethatpassinga
passwordinargumentsisinsecure.
--password-fileVAL:Filethatcontainsthepassword
28.logoutDeletesthecredentialstoredwiththelogincommand.注销
29.mailReadsstdinandsendsthatoutasane-mail.
30.offline-nodeStopusinganodeforperformingbuildstemporarily,untilthenext"online-node"command.
31.online-nodeResumeusinganodeforperformingbuilds,tocancelouttheearlier"offline-node"command.
32.quiet-downQuietdownJenkins,inpreparationforarestart.Don?.startanybuilds.
33.reload-configurationDiscardalltheloadeddatainmemoryandreloadeverythingfromfilesystem.Usefulwhenyoumodifiedconfigfilesdirectlyondisk.重新加载配置文件无参数
34.restartRestartJenkins重启Jenkins
35.safe-restartSafelyrestartJenkins安全重启Jenkins,即等待已有的构建完成再重启
36.safe-shutdownPutsJenkinsintothequietmode,waitforexistingbuildstobecompleted,andthenshutdownJenkins.安全关闭Jenkins
37.session-idOutputsthesessionID,whichchangeseverytimeJenkinsrestarts
38.set-build-descriptionSetsthedescriptionofabuild.为已有构建添加描述
参数说明:
JOB:Nameofthejobtobuild
BUILD#:Numberofthebuild
DESCRIPTION:Descriptiontobeset.'='toreadfromstdin.
--usernameVAL:UsernametoauthenticateyourselftoJenkins
--passwordVAL:Passwordforauthentication.Notethatpassinga
passwordinargumentsisinsecure.
--password-fileVAL:Filethatcontainsthepassword
39.set-build-display-nameSetsthedisplayNameofabuild重命名默认的构建编号
参数说明:
JOB:Nameofthejobtobuild
BUILD#:Numberofthebuild
DISPLAYNAME:DisplayNametobeset.'-'toreadfromstdin.
--usernameVAL:UsernametoauthenticateyourselftoJenkins
--passwordVAL:Passwordforauthentication.Notethatpassinga
passwordinargumentsisinsecure.
--password-fileVAL:Filethatcontainsthepassword
40.set-build-parameterUpdate/setthebuildparameterofthecurrentbuildinprogress
参数说明:
NAME:Nameofthebuildvariable
VALUE:Valueofthebuildvariable
--usernameVAL:UsernametoauthenticateyourselftoJenkins
--passwordVAL:Passwordforauthentication.Notethatpassinga
passwordinargumentsisinsecure.
--password-fileVAL:Filethatcontainsthepassword
41.set-build-resultSetstheresultofthecurrentbuild.Worksonlyifinvokedfromwithinabuild.
42.shutdownImmediatelyshutsdownJenkinsserver立即关闭jenkins
43.update-jobUpdatesthejobdefinitionXMLfromstdin.Theoppositeoftheget-jobcommand
44.update-nodeUpdatesthenodedefinitionXMLfromstdin.Theoppositeoftheget-nodecommand
45.versionOutputsthecurrentversion.查看当前版本
46.wait-node-offlineWaitforanodetobecomeoffline
47.wait-node-onlineWaitforanodetobecomeonline
48.who-am-iReportsyourcredentialandpermissions查看当前登录用户
Tips:为了操作方便,建议先通过login命令保存登录状态,这样就不需要每次执行操作都加上用户名密码参数了;缺点是安全性不好,记得操作结束之后logout