Hudson with Subversion: build after commit on Windows using Java or Ant
Asked Answered
A

4

5

My task is to make Hudson starting a new build after a commit. As I've read here it is done by using svn post-commit hook. The problem is I don't want to use VBScript so that is is platform-dependent. As I can see the only important things in this VBScript are using svnlook command and http://server/subversion/${UUID}/notifyCommit?rev=$REV url. As far as I am concerned I can do the same thing just using, for example, a java program (which requires parameters as revision, repository location, etc.)

Can you, please, unravel the mystery of the http://server/subversion/${UUID}/notifyCommit?rev=$REV url? I need all possible variants. It would be great if sombody can describe the whole process of interaction with Hudson (it's internal processes' chain which execute after it gets this request)

EDIT I really need the post-commit behavior, not a polling mechanism.

Arrive answered 26/8, 2011 at 8:35 Comment(4)
Why do you need post-commit behaviour? Polling is as legitimate as push notification.Goatee
Because normally, our team use this repository no more than once a week. But it is possible to have some circumstances under which commits can be more often. The traffic is critical. So that the decision was made. =)Arrive
You can set the polling interval to something like very 15 minutes or hour if you don't want to incur polling load on every minute. I'm sure your team can wait 15 minutes after the checkins.Discursion
Well, it is an idea. but not what I really need. =) As I've written, I need a post-commit behavior.Arrive
K
4

The quickest, cross platform solution is to install Cygwin on the SVN server (assuming the SVN box is running Windows) and use the suppiled shell script:

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/subversion/${UUID}/notifyCommit?rev=$REV

I need all possible variants of http://server/subversion/${UUID}/notifyCommit?rev=$REV

Why? That one does all you need.

  • server The Jenkins server
  • ${UUID} The unqiue ID for the repository.
  • $REV The new revision.

You could also just use something in the post-commit hook to ping: http://YOURHOST/jenkins/job/PROJECTNAME/build. You will not get a fresh build for every commit, but if you have two commits within seconds of each other do you really want each built?


Just out of curiosity, do you want the post commit as you have found your SVN server getting incredibly slow? If so, what OS is the SVN box on? You might be hitting limits of the OS and you would get much better performance (on the same tin) if you moved to Linux or a server edition of Windows.

Knorring answered 29/8, 2011 at 12:43 Comment(5)
Thank you very much for your answer. Making Windows to behave as Linux seems a bit overhead. On the other hand it has become a challenge to make it work on pure Windows. The 'ping' idea is really helpful!Arrive
to mlk: the main reason is not performance. It is more to architectural issue. Something like a post office. You can check if there is a letter for you every hour or you can wait for a notification.Arrive
And UUID is an id which SVN dedicates to the repository (on creation) or it is an id on which Hudson registers the current repository (and then how can I know it?) ?Arrive
The UUID is an SVN UUID. The SVN command svnlook uuid svn://svn/repository will tell you it. I consider Cygwin a standard part of any developer machine set up, so IMO the overhead is none existent.Knorring
Regarding the reason: I'd recomend you just go with hitting the YOUR_JENKINS_HOST/jenkins/job/PROJECTNAME/build then. Withwget (or alike) it is a simple one line bat script.Knorring
S
2

You don't necessarily need to use a svn hook. Just make Hudson poll the repo for changes frequently. Additionally you might want to employ a quiet period in order to account for multiple commits in a row (which otherwise might trigger multiple builds).

From the link you posted:

Jenkins can poll Subversion repositories for changes, and while this is reasonably efficient, this can only happen up to every once a minute, so you may still have to wait a full minute before Jenkins detects a change.

I wouldn't consider having to wait a minute that big a problem. In most cases you might not even notice it.

Stokowski answered 26/8, 2011 at 8:43 Comment(0)
V
1

I've done it like this: I configured hudson to check every minute for changes (Pattern: * * * * *). It works quite good. The only problem which can occur is that if two projects which have been commited within this interval and are dependent on each other, that hudson builds the wrong one first.

Viscous answered 26/8, 2011 at 8:47 Comment(0)
M
1

Important - None of the article on web clearly mentions about the job that you have to create with "Trigger Build Remotely" checked. This is the first step and this step itself gives you URL that you have to put in your subversion HOOK scriptHere is what you have to select while creating your job that would be called when commit occurs

corresponding hook script

!/bin/sh

REPOS="$1"
REV="$2"
/usr/bin/wget \
--header "Content-Type:text/plain;charset=UTF-8" \
--post-data "`/usr/local/bin/svnlook changed --revision $REV $REPOS`" \
--output-document "-" \
--timeout=2 \
http://build.development.com:8080/job/HdsVp/build?token=SVN_CHANGE
Militia answered 30/7, 2013 at 15:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.