哪个URL将获得上一个Jenkins作业的状态码(结果)? [英] What URL will get the status code (result) of the last Jenkins job?
问题描述
我想知道是否有人知道需要什么URL(作为GET或POST),它将获取上一个Jenkins作业的状态代码(结果)(当调用GET请求的客户端不知道build#时) ?我只想能够检测出结果是红色还是绿色/蓝色.
I am wondering if anyone knows what URL is required (as a GET or POST) that will get the status code (result) of the last Jenkins job (when the build# is not known by the client calling the GET request)? I just want to be able to detect if the result was RED or GREEN/BLUE .
我有此代码示例,但是我需要对其进行调整,以使其适用于Jenkins(如上所述):
I have this code sample, but I need to adjust it so that it works for Jenkins, for this purpose (as stated above):
public class Main {
public static void main(String[] args) throws Exception {
URL url = new URL("http://localhost/jenkins/api/xml");
Document dom = new SAXReader().read(url);
for( Element job : (List<Element>)dom.getRootElement().elements("job")) {
System.out.println(String.format("Name:%s\tStatus:%s",
job.elementText("name"), job.elementText("color")));
}
}
}
一旦找到答案,我将分享一个完整的示例来说明如何使用它.我想创建一个工作,以收集包含20多个工作的测试套件中的信息,并通过电子邮件报告所有这些工作.
Once I figure out the answer, I will share a full example of how I used it. I want to create a job that collects information on a test suite of 20+ jobs and reports on all of them with an email.
推荐答案
您可以使用符号描述符lastBuild
:
You can use the symbolic descriptor lastBuild
:
http://localhost/jenkins/job/<jobName>/lastBuild/api/xml
result
元素包含描述构建结果的字符串.
The result
element contains a string describing the outcome of the build.
这篇关于哪个URL将获得上一个Jenkins作业的状态码(结果)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!