What URL will get the status code (result) of the last Jenkins job?

人盡茶涼 提交于 2020-04-08 08:54:52

问题


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 .

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")));
        }
    }
}

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.


回答1:


You can use the symbolic descriptor lastBuild:

http://localhost/jenkins/job/<jobName>/lastBuild/api/xml

The result element contains a string describing the outcome of the build.



来源:https://stackoverflow.com/questions/16445315/what-url-will-get-the-status-code-result-of-the-last-jenkins-job

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!