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.
For a locally hosted Jenkins server, the URL would be: http://localhost:8080/env-vars.html. The easiest way to see how these Jenkins environment variables work is to create a freestyle job, echo each entry in the list and see the value Jenkins assigns to each property.
Navigate to the Jenkins dashboard and select Build History. This timeline displays your build history. This table displays a list of your past builds, time since build and the status of each build.
Go to Script Console under Manage Jenkins, this script will print the name of all jobs including jobs inside of a folder and the folders themselves: Jenkins. instance. getAllItems(AbstractItem.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With