Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trigger Hudson build on SVN commit

Tags:

svn

build

hudson

I have already set up a version control system (Subversion) which is going to be used by developers to commit and update their code (let's say that its address is https://server/svn/project). Only authenticated users will be able to have access to project's SVN.

On the other hand, I have installed Hudson as the project's continuous integration server (address of the project is server:8080/job/project).

I'd like to achieve the following:

  • Hudson builds to be triggered automatically when there is an SVN commit.
  • Mails are sent to the respective developers (the ones that committed code) when their committed code doesn't build, meaning that when user A commits code that doesn't build, only user A gets an email containing the notification.

I have set up matrix-based authorization for Hudson users, because I don't want to be open to anyone.

I have seen some suggestions for post-commit hooks, but none of them worked until now.

Can somebody suggest what to do regarding both issues? Specific steps would be appreciated.

like image 321
canadiangeo Avatar asked Jan 25 '11 10:01

canadiangeo


3 Answers

According to "Building a software project # Builds by changes in Subversion/CVS", Hudson needs to poll your SVN repo in order to detect changes and trigger the build.

However, that can be initiated on each commit from the SVN, like in this thread.
The official script is at the Subversion Plugin page.

REPOS="$1"
REV="$2"
UUID=`svnlook uuid $REPOS`
/usr/bin/wget \
  --header "Content-Type:text/plain;charset=UTF-8" \
  --post-data "`svnlook changed --revision $REV $REPOS`" \
  --output-document "-" \
  --timeout=2 \
  http://server/hudson/subversion/${UUID}/notifyCommit?rev=$REV

But it is specified:

For this to work, your Hudson has to allow anonymous read access to the system.
If access control to your Hudson is more restrictive, you may need to specify the username and password, depending on how your authentication is configured.

like image 56
VonC Avatar answered Nov 15 '22 21:11

VonC


To trigger a build when there is a commit in SVN you have to (1) set your hudson job to build remotely and (2) make a SVN hook...

the first part is fairly straightforward... to make the hook go to /var/lib/svn//hooks and rename post-commit.tmpl to post-commit there you can do something like

#!/bin/bash
# Este script comprueba si se han hecho cambios en un directorio concreto,
# y en tal caso lanza una build en Jenkins

REPOS="$1"
REV="$2"
JENKINS_JOB="$3"
JENKINS_USER=admin
JENKINS_PASSWORD=****
JENKINS_HOST=<hostname>

if [ -n $(svnlook dirs-changed $REPOS --revision $REV | fgrep "tags\/") ];then
 wget --quiet --auth-no-challenge --no-check-certificate --http-user=$JENKINS_USER --http-password=$JENKINS_PASSWORD http://$JENKINS_HOST/job/$JENKINS_JOB/build?token=TOKEN
fi

exit 0

Look at this article http://blogsyntagma.blogspot.com.ar/2012/04/hook-de-subversion-para-ejecutar-un-job.html (it's in spanish)

like image 37
diegobalseiro Avatar answered Nov 15 '22 22:11

diegobalseiro


Here are the required steps:

  • Create a SVN user that Hudson can use to gain read-only access to your repository
  • Configure Hudson to use this SVN user when accessing the repository
  • Create a new job to use the repository at a specified address (i.e. a specific branch)
  • Configure your job to poll the repository at least once a minute for any changes
  • Configure your job to build what is required
  • Configure your job to send an e-mail on build failure

I would recommend e-mailing all developers so that they are notified that the build is unstable, not just the culprit. Not only does this provide more visibility, but it will motivate the culprit to fix the problem immediately or otherwise accept a scolding from their fellow developers. Trust me, this is effective.

like image 33
Bernard Avatar answered Nov 15 '22 21:11

Bernard