Jenkins - Configure Jenkins to poll changes in SCM

前端 未结 3 459
难免孤独
难免孤独 2021-02-02 05:36

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

相关标签:
3条回答
  • 2021-02-02 05:40

    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.

    0 讨论(0)
  • 2021-02-02 05:46

    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.

    0 讨论(0)
  • 2021-02-02 06:04

    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:

    • Jenkins Wiki's post-commit hook description on Subversion Plugin's doc-site. Here you find documented example of the script you are interested in.
    • Hook-scripts contrib directory in the source of official Apache Foundation's Subversion's source control repository.
    • Similar question on StackOverflow.

    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
    
    0 讨论(0)
提交回复
热议问题