Trouble with SVN post-commit and Jenkins
Asked Answered
P

5

8

I am trying to get CI going with Jenkins. To date, we have been performing two scheduled builds in our environment, but our dev staff wants to get CI working. I have followed the instruction outlined in the Jenkins Subversion Plugin wiki page:

https://wiki.jenkins-ci.org/display/JENKINS/Subversion+Plugin

This got me to a script that executes at the command line just fine, however when I commit a change in Subversion (using the TortoiseSVN client), the commit seems to hang and I don't see Jenkins getting notified.

Here is my script:

#!/bin/sh

REPOS="$1"
REV="$2"
UUID=`svnlook uuid $REPOS`
XSLT_FILE=/var/www/svn/codelog.xslt
RSS_FILE=/var/www/html/code_all.rss
MAX_RESULTS=40

/usr/bin/wget \
  --auth-no-challenge \
  --no-check-certificate \
  --header "Content-Type:text/plain;charset=UTF-8" \
  --post-data "`svnlook changed --revision $REV $REPOS`" \
  --output-document "-" \
  --timeout=2 \
  https://192.168.100.16/subversion/${UUID}/notifyCommit?rev=$REV
svn log "file://$REPOS" --limit "$MAX_RESULTS" -v --xml | xsltproc "$XSLT_FILE" - > "$RSS_FILE"

The RSS feed was already in the script. That has been working for over a year.

I have updated the file permissions as well, in case that was the problem:

[root@Subversion hooks]# ls post-commit -ao
-rwxrwxr-x 1 apache 530 Jul 17 06:27 post-commit
Pucka answered 17/7, 2012 at 11:13 Comment(3)
Which version of Jenkins are you using?Indoiranian
currently using version 1.467... ALSO: * have Poll SCM setup for all jobs * using CROWD for authenticationPucka
For starters, call that URL from a browser (you'll need to find out the UUID of the repository for that - use svnlook as it is used in the hook). See if it starts the build.Stand
I
1

I have never liked how the SVN Plugin page is written. It is to easy to read it to say that you need to set up a Post Commit Hook in SVN to make things work. You Don't!

We have about 10 builds on our Jenkins box. All of them are linked to SVN repositories, and all a triggered by changes in the SVN repository. None of them rely on having to use a Post Commit Hook in SVN.

To do this, we have configured the builds to simply "Poll SCM" on a schedule. The "commit" builds use a schedule of "*/5 * * * *". This polls every 5 minutes. Our "daily" builds use a schedule of "1 1 * * *" so that the builds would kick off at 1:01 AM if there are any changes.

Insulting answered 17/7, 2012 at 15:11 Comment(5)
I get your point, almost ready to go to this option, but still want to see if I can get the push notify to work.Pucka
this has become my choice. didn't answer the initial question, but everyone in my group is satisfied.Pucka
I'm afraid this is a very bad solution. Here's why: this would be fine... for a while. Once you start having like... 200-300 jobs, you will start noticing errors trying to even connect to Subversion from that machine. Look around Google. Look around the Jenkins JIRA. You'll see what I mean. The polling starts not working.Isolationism
@Isolationism Good info to know. For my application, its not a problem but when we grow it I will keep it in mind.Insulting
Yeah, we used to use it like this and I indeed had it set to */5 * * * * (back then) but soon we started hitting the issue. The problem is that this particular issue has not been resolved even now and this is the reason why most people with a large amount of modules simply choose to get the svn hook part working and set a */30 * * * * interval.Isolationism
I
5

In order to enable push mode in Jenkins, you should enable the Poll SCM build trigger in configuration page of your job. It tells Jenkins that it should build the job whenever SCM changes occur.

Because you don't have to do any polling (you get the info from the hook) you can leave the field blank.

Indoiranian answered 17/7, 2012 at 12:40 Comment(1)
thanks, Yossi, appreciate you taking a look at this. I do have the Poll SCM setup on my jobs in Jenkins. Currently have the interval set at "@yearly", but good to know that I can leave it blank! Please note that this does work if I trigger from the command line, just does not work when a user commits change.Pucka
I
2

Try increasing your timeout -- 2 seconds is like... Too low.

This is what works for me:

/usr/bin/wget --http-user=jenkins \
              --http-passwd=passwordGoesHere \
              --header "Content-Type:text/plain;charset=UTF-8" \
              --post-data "`svnlook changed --revision $REV $REPOS`" \
              --output-document "/var/log/svn/svn-notify-commit-post" \
              --timeout=10 \
              --read-timeout=10 \
              --tries=2 \
              "http://jenkins:8082/jenkins/subversion/${UUID}/notifyCommit?rev=$REV" \
              >> /var/log/svn/svn-notify-commit-post.log 2>&1

(Make sure you have a /var/log/svn directory owned by the proper user).

Also, enable SCM polling and set a cron rule like */30 * * * *.

Isolationism answered 17/7, 2012 at 14:1 Comment(1)
I am getting logged information now from command line... still nothing from a commit, though. appears as though it is never calling the script, but I know that it is because the RSS part of script is working. That file is getting updated every timePucka
C
2

Please take a look at your URL. Since Jenkins is a web application running in a servlet container the following one must work:

http(s)://server_name:server_port/application_name/subversion/${UUID}/notifyCommit?rev=$REV"

The idea is to pass

"subversion/${UUID}/notifyCommit?rev=$REV"

to the right place.

Carmacarmack answered 26/2, 2013 at 16:13 Comment(0)
I
1

I have never liked how the SVN Plugin page is written. It is to easy to read it to say that you need to set up a Post Commit Hook in SVN to make things work. You Don't!

We have about 10 builds on our Jenkins box. All of them are linked to SVN repositories, and all a triggered by changes in the SVN repository. None of them rely on having to use a Post Commit Hook in SVN.

To do this, we have configured the builds to simply "Poll SCM" on a schedule. The "commit" builds use a schedule of "*/5 * * * *". This polls every 5 minutes. Our "daily" builds use a schedule of "1 1 * * *" so that the builds would kick off at 1:01 AM if there are any changes.

Insulting answered 17/7, 2012 at 15:11 Comment(5)
I get your point, almost ready to go to this option, but still want to see if I can get the push notify to work.Pucka
this has become my choice. didn't answer the initial question, but everyone in my group is satisfied.Pucka
I'm afraid this is a very bad solution. Here's why: this would be fine... for a while. Once you start having like... 200-300 jobs, you will start noticing errors trying to even connect to Subversion from that machine. Look around Google. Look around the Jenkins JIRA. You'll see what I mean. The polling starts not working.Isolationism
@Isolationism Good info to know. For my application, its not a problem but when we grow it I will keep it in mind.Insulting
Yeah, we used to use it like this and I indeed had it set to */5 * * * * (back then) but soon we started hitting the issue. The problem is that this particular issue has not been resolved even now and this is the reason why most people with a large amount of modules simply choose to get the svn hook part working and set a */30 * * * * interval.Isolationism
A
0

Did you check if you have SELinux enabled?

I had the same problem and wrote a solution here https://mcmap.net/q/348331/-can-39-t-open-file-39-svn-repo-db-txn-current-lock-39-permission-denied

The error I was getting was that it could not connect to the url (but when invoking it from commandline it did work).

Achondrite answered 14/3, 2013 at 12:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.