Let's say that you have an issue on a given Jenkins agent at a given time, but you don't know which build can cause it. Here is how to find out which builds where running on that agent, at that time.
In this case, the agent is an AWS EC2 VM, with a well known instance ID (in this case, i-02d41abc1a375089d
).
This works with Jenkins organization folders.
from $JENKINSHOME/jobs
:
find . -name "build.xml" -exec grep "i-02d41abc1a375089d" {} \; -exec ./deslash.sh {} ";"
with deslash.sh
:
#!/bin/bash
cp "$1" /tmp/"${1//\//_}"
The result is a list of build.xml files, in your /tmp
directory.
Then, from /tmp
, run: find . -name "*build.xml" -exec ./check.sh {} ";"
with exec.sh
:
#!/bin/bash
EVENTTIME=1625489553
STARTTIMEMS=$(grep -oPm1 "(?<=<startTime>)[^<]+" "$1")
DURATIONMS=$(grep -oPm1 "(?<=<duration>)[^<]+" "$1")
let STARTTIME=STARTTIMEMS/1000
let DURATION=DURATIONMS/1000
let ENDTIME=$(( $STARTTIME + $DURATION ))
if [ "$STARTTIME" -lt "$EVENTTIME" ] && [ "$ENDTIME" -gt "$EVENTTIME" ]; then
echo "Start: $STARTTIME - end: $ENDTIME: Job occured during the event: $1";
fi
Note: 1625489553
here is the timestamp of the event (Epoch time).
Result:
Start: 1625489504 - end: 1625492344, duration: 2840: Job occured during the event: ./._ABC-Automation_jobs_datahub-documentation.edfgeb_branches_master_builds_580_build.xml
Start: 1625485473 - end: 1625496933, duration: 11460: Job occured during the event: ./._tyu-policy-art_jobs_policy_branches_master_builds_229_build.xml
Start: 1625483101 - end: 1625492458, duration: 9357: Job occured during the event: ./._CustomerEngagement_jobs_uiiuaz_branches_master_builds_4500_build.xml
Start: 1625467385 - end: 1625489851, duration: 22466: Job occured during the event: ./._aozia_jobs_test-database-upgrade_branches_master_builds_512_build.xml
Start: 1625489112 - end: 1625490185, duration: 1073: Job occured during the event: ./._ABC-Automation_jobs_metadata-configurator.omdm4g_branches_master_builds_867_build.xml
Start: 1625487048 - end: 1625496789, duration: 9741: Job occured during the event: ./._tyu-policy-art_jobs_policy-db-load_branches_master_builds_294_build.xml