Thursday, May 17, 2012

Get latest successful build number from Bamboo

This little script gets the latest successful build number.


SAVEIFS=$IFS
IFS=$'\n'
for ln in `wget -O- --quiet --http-user="{user name}" --http-password="{user password}" 'http://{bamboo site url}/rest/api/latest/build/{plan key}?os_authType=basic' | tr '<' '\n'`
do
  build_number=`echo $ln | perl -n -e 'm/number="([\s\S]+?)" lifeCycleState="Finished" state="Successful"/ && {print "$1\n"}'`
  if [ $build_number ] 
  then
     break
  fi
done
IFS=$SAVEIFS
echo "Latest successful build number $build_number"


Once you have the build number, you can use that to get latest code coverage, artifacts etc. Get the url for the intended resource and substitute with the $build_number variable above