我怎么知道jenkins构建是否已在Python中启动?

时间:2019-05-29 21:57:46

标签: python jenkins jenkins-cli

我用Python编写了一个脚本,在其中我通过cli启动了Jenkins构建:

import subprocess
command = "curl -s -X POST  http://<user>:<token>@<server>/build"
subprocess.Popen(command)

我需要找到一种检查构建状态的方法,例如:

If not started : Wait to start
If started : on progress
If ended : Success / Failure

这样做:

while True:
    # Check the status of the build
    # ... <----- I don't know what to do here

    if STATUS == "on progress"
        break

感谢您的建议

1 个答案:

答案 0 :(得分:2)

您可以使用此端点:

http://my-jenkins.com/job/job_name/lastBuild/api/json

检查此链接以查看python实现:

https://serverfault.com/a/309917/490115