Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a list of Jenkins builds that ran at a particular time?

Tags:

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?

like image 327
Amanjeet Singh Avatar asked Nov 12 '18 04:11

Amanjeet Singh


People also ask

How do I see scheduled builds in Jenkins?

Press the "Schedule Build" link on the project page or use the schedule build action in the list view.

How do I find the builds in Jenkins?

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.

How do I get a list of all jobs in Jenkins?

Get a list of jobs. This can be done requesting http://jenkins_url:port/api/json?tree=jobs[name,url] .


1 Answers

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
like image 105
Chris Maes Avatar answered Oct 03 '22 22:10

Chris Maes