环境:Jenkins V2.150.1
获取所有job名称
命令:
1 | # 获取crumb |
示例:
1 | [root@lzzeng opt]#curl -sX GET 'http://188.131.xxx.xxx:8088/jenkins/api/json?pretty=true' -H Jenkins-Crumb:a1b3b82a61bf4672e6d9003de37xxxxx -u "$jenkins_user:$jenkins_password" |grep '"url"' |grep '/job/' |sed -e 's@^.*job/\(.*\)/.*$@\1@' |
构建job
命令:
1 | # 无参数构建 |
示例:
1 | [root@lzzeng opt]# curl -sX POST http://188.131.xxx.xxx:8088/jenkins/job/test_job/build -u "$jenkins_user:$jenkins_password" -H Jenkins-Crumb:a1b3b82a61bf4672e6d9003de37xxxxx |
查看Jenkins,可以看到参数传递正确:
禁用job
命令:
1 | curl -sX POST "$jenkins_url/job/$job_name/disable" -u "$jenkins_user:$jenkins_password" -H "$crumb" |
示例:
1 | [root@lzzeng opt]# curl -sX POST http://188.131.xxx.xxx:8088/jenkins/job/test_job_with_parameter/disable -u "$jenkins_user:$jenkins_password" -H Jenkins-Crumb:a1b3b82a61bf4672e6d9003de37xxxxx |
获取构建结果
命令:
1 | # 最近一次构建结果 |
示例:
1 | [root@lzzeng opt]# curl -sX POST http://188.131.xxx.xxx:8088/jenkins/job/test_job_with_parameter/lastBuild/api/json?pretty=true -u "$jenkins_user:$jenkins_password" -H Jenkins-Crumb:a1b3b82a61bf4672e6d9003de37xxxxx |
如果要获取插件的结果,可以尝试添加请求参数depth=2
,即变成api/json?pretty=true&depth=2
(End)