Using Nerrvana – SVN hooks to Jenkins

Using Nerrvana - SVN hooks to Jenkins

Part 1 – Using Nerrvana – our setup
Part 2 – Using Nerrvana – SVN hooks to Jenkins – this post
Part 3 – Using Nerrvana – deployment & Jenkins (part 1)
Part 4 – Using Nerrvana – deployment & Jenkins (part 2)

Firstly I set up an SVN server. I decided not to disturb Vadym, and found good instructions to follow (good links tend to become broken with time so I saved a screenshot for you if this happens).

I took the project we test with Selenium from our main repository and imported it into my own SVN server that I just set up.

Following the instructions above I also added ‘jenkins’ SVN user and saved his password to use later during Jenkins set up.

Now we create the file – post-commit-hook-for-jenkins in /var/www/svn/answers/hooks/ (‘answers’ is a repo name).

#!/bin/sh
JENKINS="http://192.168.3.97:8080"
 
REPOS="$1"
REV="$2"
 
WGET="/usr/bin/wget -q"
SVNLOOK=/usr/bin/svnlook
HOME=/var/www/
UUID=`$SVNLOOK uuid $REPOS`
NOTIFY_URL=subversion/$UUID/notifyCommit?rev=$REV
CRUMB_ISSUER_URL='crumbIssuer/api/xml?xpath=concat(//crumbRequestField,":",//crumb)'
 
function notifyCI {
  CISERVER=$1
  HEADER="Content-Type:text/plain;charset=UTF-8"
  CRUMB=`$WGET --auth-no-challenge --output-document - $CISERVER/$CRUMB_ISSUER_URL`
  if [ "$CRUMB" != "" ]; then HEADER=$CRUMB; fi
 
  POST=`$SVNLOOK changed --revision $REV $REPOS`
#  echo $POST >> /tmp/post-commit$REV.log 2>&1
 
  $WGET \
    --auth-no-challenge \
    --header $HEADER \
    --post-data "$POST" \
    --output-document "-"\
    --timeout=2 \
    $CISERVER/$NOTIFY_URL
}
notifyCI $JENKINS
>> /tmp/post-commit$REV.log 2>&1

More detailed info about setting SVN hooks is available in Jenkins documentation.

Now we change post-commit hook by adding our Jenkins hook call:

#!/bin/sh
REPOS="$1"
REV="$2"
 
/var/www/svn/answers/hooks/post-commit-hook-for-jenkins $REPOS $REV

Check access rights to files. Note – Selinux is turned off on my server:

#ls -la /var/www/svn/answers/hooks/
 
-rwxr-xr-x 1 apache apache   99 Jul  9 14:46 post-commit
-rwxr-xr-x 1 apache apache  822 Jul  9 14:25 post-commit-hook-for-jenkins

Now we can uncomment the last line in post-commit-hook-for-jenkins file and make a test commit. If we have a new file in /tmp directory – we have completed SVN server and Jenkins hook set up.

In our next post – read about web application deployment with Jenkins.

Print this post | Home

Comments are closed.