My current Jenkins has a large number of jobs. Different folders, each with multiple jobs. I recently saw that one Jenkins slave(which is auto-scaled) is sending too many requests to another server at a particular time. However, I am unable to find which builds are run at that particular time without manually checking them. Is there any way to get this information using the API/Groovy script?
Press the "Schedule Build" link on the project page or use the schedule build action in the list view.
Every page in Jenkins has a search box on its top right that lets you get to your destination quickly, without multiple clicks. For example, if you type "foo #53 console", you'll be taken to the console output page of the "foo" job build #53.
Get a list of jobs. This can be done requesting http://jenkins_url:port/api/json?tree=jobs[name,url] .
I wrote a very small bash script to run on the jenkins server to parse through the logfiles.
It is not sufficient to look only at the job start time. A job could have started just before your time window and even ended after your time window; it would still have run within your time window.
#!/bin/bash
start=$1
end=$2
for build_xml in jobs/*/branches/*/builds/*/build.xml
do
startTime=$(sed -n -e "s/.*<startTime>\(.*\)<\/startTime>.*/\1/p" $build_xml)
modificationTime=$(date '+%s' -r $build_xml)
if [[ $modificationTime > $start ]] && [[ $startTime < $end ]]
then
echo "START $(date -d @${startTime::-3}) END $(date -d @$modificationTime) : $build_xml"
fi
done
usage:
./getBuildsRunningBetween.sh 1565535639 1565582439
would give:
START Sun Aug 11 20:29:00 CEST 2019 END Sun Aug 11 20:30:20 CEST 2019 : jobs/job-name/branches/branch-name/builds/277/build.xml
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