65

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

starball
  • 20,030
  • 7
  • 43
  • 238
Blanca Hdez
  • 3,513
  • 19
  • 71
  • 93

3 Answers3

110

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.

Liam
  • 27,717
  • 28
  • 128
  • 190
Ashley Frieze
  • 4,993
  • 2
  • 29
  • 23
  • 8
    Indeed, Jenkins (two years later) will now throw the following warning `Spread load evenly by using ‘H/5 * * * *’ rather than ‘*/5 * * * *’`. – msanford Apr 22 '16 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 * * * *" – Ripunjay Godhani Mar 19 '18 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.

Liam
  • 27,717
  • 28
  • 128
  • 190
  • 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 – Blanca Hdez Apr 12 '12 at 12:43
  • That is a web server specific question which I can't really answer –  Apr 12 '12 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 – Edgar Villegas Alvarado Nov 23 '12 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 Jul 24 '14 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 Oct 14 '14 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
Remik
  • 140
  • 1
  • 7