Jenkins--02命令行构建Job

1.查看说明并下载文件

1.1 下载jenkins-cli.jar:http://127.0.0.1:8080/jenkins/cli

1.2 jenkins-cli.jar命令帮助:java -jar jenkins-cli.jar -s http://127.0.0.1:8080/jenkins/ -help

 

2.使用build命令构建一个Job

java -jar jenkins-cli.jar -s http://127.0.0.1:8080/jenkins/  build JOBNAME -p tag=xxx --username xxx --password xxx
 
说明:
1.build后面直接跟JOB的名字
2.-p后面跟参数化构建的参数,使用key=value格式。如果有多个参数就写多个-p
3.—username和--password提供jenkins的账号密码
 

build的使用方法:
JOB : Name of the job to build
    要创建的作业的名称
-c  : Check for SCM changes before starting the build, and if there's no change, exit without doing a build
    在开始构建之前检查SCM更改,如果没有更改,退出而不进行构建
-f  : Follow the build progress. Like -s only interrupts are not passed through to the build.
    按照生成进度。像-s仅中断不会传递给构建。
-p  : Specify the build parameters in the key=value format.
    在KEY=值格式中指定生成参数
-s  : Wait until the completion/abortion of the command. Interrupts are passed through to the build.
    等待命令完成/堕胎。中断被传递到构建。
-v  : Prints out the console output of the build. Use with -s
    打印出构建的控制台输出。使用-s
-w  : Wait until the start of the command
    等待命令的开始

3.获得历史构建的参数

获取上次构建结果:
curl  "http://127.0.0.1:8080/jenkins/view/app/job/JOBNAME/lastBuild/api/xml”
 
然后可以解析结果,可以通过expr在shell中解析,获得需要的参数,例如获得tag:
expr "$result" : '.*<name>tag</name><value>\([a-zA-Z0-9_-]*\)</value></parameter>'
 
说明:$result为请求上次构建的结果,tag这里匹配的是字母数字和下划线中横线

 

以上内容参考地址:https://www.cnblogs.com/meitian/p/7609178.html

posted on 2018-07-22 15:21  CevinChen  阅读(1132)  评论(0编辑  收藏  举报