Why Does Jenkins REST API Return {} While Console Logs Show Build Output?

I am trying to fetch data from a Jenkins public instance (ci.jenkins.io) using the REST API.

When I use

import requests
url = "https://ci.jenkins.io/job/Websites/job/jenkins.io/job/master/lastBuild/api/json"
response = requests.get(url)
print(response.json())

It returns {}.

However, fetching logs works fine:

import requests
url = 'https://ci.jenkins.io/job/Websites/job/jenkins.io/job/master/lastBuild/consoleText'
response = requests.get(url)
print(response.text)

Why does the API return {} and not build details (like result, changeSets, duration)?
Could someone share a Python code example that returns non-empty JSON data using the REST API?

When you try to fetch the data as XML you get redirected to Redirects from ci.jenkins.io
So maybe it is intentional not to return that data

1 Like

You’ll need to run your own instance of Jenkins to gather that type of data rather than gathering it from ci.jenkins.io.

1 Like

@mawinter69 and @MarkEWaite Thanks for the info .
I am aiming to contribute to the gsoc project Domain-Specific LLM for Jenkins . For this project mentors specified to use Rest API to get ci.jenkins.io data and not to web scrape.
Since Rest API is not providing the necessary info, Is it acceptable to use the /consoleText API endpoint for this project?
Your input will be really valuable. Thanks in advance.

I don’t think that will work. The Jenkins infra team has found that recent activity appears to be overloading ci.jenkins.io with requests. They are now considering safety measures that will prevent that type of overload from happening in the future. The overload looks suspiciously like a large language model that is pushing an enormous number of requests to ci.jenkins.io, harming its ability to perform its primary mission, running continuous integration jobs for Jenkins contributors.

1 Like

@MarkEWaite Sir thanks for the info.
But if web scraping and /consoleText API not acceptable and the Rest API not able to gather data from ci.jenkins.io, then would there be any recommended way to collect data in a compliant manner that aligns with Jenkins Infra Team’s guidelines for this project Domain-Specific LLM for Jenkins.
Any guidance you could provide would really help me prepare a stronger GSoC proposal and gain a better understanding of the project.
Thank you sir

I think that you can install your own Jenkins controller locally, run jobs on that controller, and use the results from those jobs to test drive your locally large language model.

We might also be able to persuade the Jenkins infrastructure team to provide a compressed archive of console logs that could be used as an initial sample of data. I haven’t discussed it with them, but since the instance is publicly readable, I would expect that the build logs from the jobs could be saved in a compressed archive for download by anyone that wants to use them for experimentation.

1 Like

@MarkEWaite
Thanks for your response.