#!/bin/bash
# (c) 2014 Steve Parker, steve@steve-parker.org
# http://steve-parker.org/code/sh/buildhistory/
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 2 of the License only.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
# Edit to suit:
W=40 # Max width of a project name
BASE=/var/lib/jenkins # Jenkins home
cleanup() {
tput sgr0
}
trap cleanup 0
header()
{
echo "Build history for Jenkins slave: $@"
printf "%-${W}s %s\n" Project "Date/Time Status"
}
buildhistory()
{
SLAVE=$@
cd $BASE
grep -F "$SLAVE" config.xml > /dev/null
if [ "$?" -ne "0" ]; then
echo "Usage: $0 [ -f ] SlaveName"
[ ! -z "$SLAVE" ] && echo "Slave \"$SLAVE\" not found in config.xml"
exit 1
fi
tput sgr0
for project in $BASE/jobs/*
do
cd "$project/builds" || continue
projectname=`basename "$project"`
#echo "Checking $projectname"
for build in */build.xml
do
[ -f "$build" ] || continue
buildname=`dirname "$build"`
if [ ! -L "$buildname" ]; then
grep -F "$SLAVE" $build > /dev/null
if [ "$?" -eq "0" ]; then
result=`grep "" $build | tail -1 | cut -d">" -f2-| cut -d"<" -f1`
printf "%-${W}s " $projectname
echo -n "$buildname = " | tr -d '-' | tr '_' '.'
case $result in
SUCCESS) tput setaf 2 ;; # green
FAILURE) tput setaf 1 ;; # red
ABORTED) tput setaf 3 ;; # yellow
NOT_BUILT) tput setaf 7 ;; # grey
UNSTABLE) tput setaf 6 ;; # cyan
*) tput setaf 5 ;; # purple
esac
echo $result
tput sgr0 # set to normal
fi
fi
done
done
}
if [ "$1" = "-f" ]; then
shift
header $@
buildhistory $@
else
header $@
buildhistory $@ | sort -n -k2
fi