Jenkins - Configure Jenkins to poll changes in SCM

前端 未结 3 458
难免孤独
难免孤独 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条回答
  •  梦毁少年i
    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
    

提交回复
热议问题