I’m trying to list out last 5 jobs run on each Jenkins agent, i used Build History option from agent details but it’s takes some time to load all details due to which i’m not able to export the metrics from Jenkins to Prometheus.
Do we have any alternative to display last 5 jobs run on agents ?
The build history of an agent that you access with the Build History link is a UI thing only. And it is limited as it is not able to list executions of pipeline jobs.
In order to get the history of an agent this will loop over all builds of all jobs and checks if the built was run on that agent so this is an expensive operation and the page will always list all jobs that have run. For pipeline jobs this information is not directly accessible as it is hidden deep in the flow information so this page is not able to find those builds.
The plugin Pipeline Agent Build History solves this by adding an additional link for agents that is able to extract that information from pipeline jobs (and it also shows freestyle jobs). It caches the builds and uses pagination which makes it pretty fast.
But the plugin has no rest api that will return e.g. some json with the last runs
Unfortunately, we have only freestyles jobs not a pipeline jobs. Still can i use Pipeline Agent Build History for freestyle jobs ? Mainly i was looking for rest api but seems that it’s not available to use.
yes the plugin also shows freestyle jobs.
There might be better solutions to keep track which jobs run on an agent for external monitoring systems, e.g. pushing this to elasticsearch, though it might require writing a new plugin (not sure if there is already a plugin for this)