What URL will get the status code (result) of Jenkins latest work?

I am wondering if anyone knows what kind of URL is required (like GET or POST) that will receive the status code (result) of the last Jenkins job (when the assembly is not known to the client calling the GET request)? I just want to find out if the result was RED or GREEN / BLUE.

I have this sample code, but I need to configure 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"))); } } } 

As soon as I find out the answer, I will share a complete example of how I used it. I want to create a task that collects information about a set of tests from 20+ tasks and reports on all of them using e-mail.

+7
source share
1 answer

You can use the lastBuild symbolic descriptor:

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

The result element contains a string describing the result of the assembly.

+12
source

All Articles