Friday, June 22, 2012

hudson

i figured out how to use a number of hudson's features for greater awesomeness in keeping my code base under control.

for svn+ssh:
on svn server: (make sure it's openssh)
ssh-keygen -t dsa -f newkey
append newkey.pub to ~/.ssh/authorized_keys
on Hudson: upload newkey as private key file

select 'trigger builds remotely'
put this script into the svn server, in hooks/post-commit
# force a build on the Continuous Integration server
echo "calling url to build r$2 in $1" >> /tmp/svnBuild
/usr/bin/wget -O - http://hudsonserver:8080/job/JobName/build?token=tokenString&cause=SVN_commit > /dev/null

to do the build, i put everything into a bash script at the root of my svn repo. so in hudson, i put this into the 'execute shell' 'command':
#!C:\cygwin\bin\bash.exe
. hudsonBuild.sh

(i also had to make a windows link from one directory to another at one point -- i didn't know how to do this before, but from cygwin you can use this:)
cmd.exe /c mklink /D testdata "c:\otherTestdata"

i also tried a few other things that i didn't end up using, mostly because their outputs didn't jive with hudson.
pylint -f parseable python > pylint.txt # i used pep8 instead
sloccount --wide --details python > sloccount.sc # i used pynocle instead

under post-build actions,
'publish junit test result report' with **/nosetests.xml as the filename
'publish covertura coverage report' with **/coverage.xml
'publish html report' with directory 'complexity' and name metrics.html, directory pynocle and name index.html
'report violations' with **/clonedigger.xml for cpd and **/pep8.txt for pylint

the hudsonBuild.sh script is like this:

echo "PATH="
echo $PATH

echo "building extension"
cd python/module/extension
/cygdrive/c/Python27/python -c 'import __init__'
cd ../../

echo "starting doctest/coverage"
#cd python
which python
echo "PYTHONPATH="
echo $PYTHONPATH
coverage run 'c:\Python27\Scripts\nosetests-script.py' --with-doctest --with-xunit --with-coverage --with-profile --profile-stats-file=nosetests.hotshot --verbose
coverage xml
mv coverage.xml coverage_nopath.xml
sed 's//D:\\Hudson\\.hudson\\jobs\\JobName\\workspace\\python<\/source><\/sources>/g' coverage_nopath.xml > coverage.xml
# put hotshot output into the html report dir, so it will get saved for each build
mv nosetests.hotshot ../complexity/
cd ..

echo "starting pep8"
pep8 --repeat python | perl -ple 's/:\d+: ([WE]\d+)/: [$1]/' > pep8.txt

echo "starting clonedigger"
clonedigger --cpd-output -o clonedigger.xml python

echo "starting pymetrics"
pymetrics `/usr/bin/find python -iname "*.py"` > $COMPLEXITY_DIR/complexity.txt

echo "starting pycabehtml"
pycabehtml.py -i $COMPLEXITY_DIR/complexity.txt -o $COMPLEXITY_DIR/metrics.html -a $ACC -g $GRAPH

echo "starting pynocle"
cd python
./pynocleGenerate.py
cd ..

echo "build script finished"

No comments: