66

I am working with jenkins and I would like to run the maven goals when there is a change in the svn repository. I've attached a picture with my current configuration.

I know that checking the repository every 5 min is crazy. I would like to run it only when there is a new change, but I could not find the way. Anyway, it is not checking the repository. What am I doing wrong?

enter image description here

3 Answers 3

111

I believe best practice these days is H/5 * * * *, which means every 5 minutes with a hashing factor to avoid all jobs starting at EXACTLY the same time.

2
  • 8
    Indeed, Jenkins (two years later) will now throw the following warning Spread load evenly by using ‘H/5 * * * *’ rather than ‘*/5 * * * *’.
    – msanford
    Commented Apr 22, 2016 at 14:37
  • 2
    yes using H/5 * * * * is the best practice to avoid error "Spread load evenly by using ‘H/5 * * * *’ rather than ‘*/5 * * * *" Commented Mar 19, 2018 at 11:55
79

I think your cron is not correct. According to what you described, you may need to change cron schedule to

*/5 * * * *

What you put in your schedule now mean it will poll the SCM at 5 past of every hour.

5
  • I have besides another questions, maybe you could help me: I hae problems with the authentification when I deploy the project. I dont know where to write the credentials. any clue? thankss Commented Apr 12, 2012 at 12:43
  • That is a web server specific question which I can't really answer
    – user454043
    Commented Apr 12, 2012 at 16:44
  • Hi Blanca, you could check the permissions that the jenkins' user has (maybe needs another user to run). On windows run services.msc, look for the jenkins project, right click, Properties -> Log on Commented Nov 23, 2012 at 12:18
  • Such a suttle change that makes a HUGE difference! (adding the */ before the 5 to go every 5 minutes instead of 5 minutes past the hour...)
    – ganders
    Commented Jul 24, 2014 at 13:14
  • 4
    Why does this get so many upvotes when its wrong? The value "*/5" is the equivilant of "0-59/5", which is 12x per hour.
    – djangofan
    Commented Oct 14, 2014 at 21:36
8

That's an old question, I know. But, according to me, it is missing proper answer.

The actual / optimal workflow here would be to incorporate SVN's post-commit hook so it triggers Jenkins job after the actual commit is issued only, not in any other case. This way you avoid unneeded polls on your SCM system.

You may find the following links interesting:

In case of my setup in the corp's SVN server, I utilize the following (censored) script as a post-commit hook on the subversion server side:

#!/bin/sh

# POST-COMMIT HOOK

REPOS="$1"
REV="$2"
#TXN_NAME="$3"
LOGFILE=/var/log/xxx/svn/xxx.post-commit.log

MSG=$(svnlook pg --revprop $REPOS svn:log -r$REV)
JENK="http://jenkins.xxx.com:8080/job/xxx/job/xxx/buildWithParameters?token=xxx&username=xxx&cause=xxx+r$REV"
JENKtest="http://jenkins.xxx.com:8080/view/all/job/xxx/job/xxxx/buildWithParameters?token=xxx&username=xxx&cause=xxx+r$REV"

echo post-commit $* >> $LOGFILE 2>&1

# trigger Jenkins job - xxx
svnlook changed $REPOS -r $REV | cut -d' ' -f4 | grep -qP "branches/xxx/xxx/Source"
if test 0 -eq $? ; then
        echo $(date) - $REPOS - $REV: >> $LOGFILE
        svnlook changed $REPOS -r $REV | cut -d' ' -f4 | grep -P "branches/xxx/xxx/Source" >> $LOGFILE 2>&1
        echo logmsg: $MSG >> $LOGFILE 2>&1
        echo curl -qs $JENK >> $LOGFILE 2>&1
        curl -qs $JENK >> $LOGFILE 2>&1
        echo -------- >> $LOGFILE
fi

# trigger Jenkins job - xxxx
svnlook changed $REPOS -r $REV | cut -d' ' -f4 | grep -qP "branches/xxx_TEST"
if test 0 -eq $? ; then
        echo $(date) - $REPOS - $REV: >> $LOGFILE
        svnlook changed $REPOS -r $REV | cut -d' ' -f4 | grep -P "branches/xxx_TEST" >> $LOGFILE 2>&1
        echo logmsg: $MSG >> $LOGFILE 2>&1
        echo curl -qs $JENKtest >> $LOGFILE 2>&1
        curl -qs $JENKtest >> $LOGFILE 2>&1
        echo -------- >> $LOGFILE
fi

exit 0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.