0
votes

I am trying to implement the CI/CD pipeline using kubernetes , Jenkins and my private SVN code repository in On-Premise server. When I watching example for implementing pipeline, I am only seeing that the usage of GitHub - Web hooks. And triggering using web hooks when a commit is made into GitHub repository. In my development scenario , I am using SVN repository. So In my previous stack overflow discussion , I found that adding one SVN plug in Jenkins. Here I had felt the doubt that ,

  1. Instead of using triggering functionality with web hooks from GitHub, What we can do for using SVN plug in ? Is there any configuration in Jenkins that saying build project , test and deploy when a commit is made into code repo? Otherwise do i need to always depend on cron jobs from jenkins?
  2. Like in GitHub - web hooks , Which is the triggering action we can configure in jenkins when a commit is made into code repo?
1

1 Answers

1
votes

The Subversion plugin page has a couple of nice examples on using post-commit hooks to get the behavior you're looking for. To answer your questions, it looks like:

  1. You can add a script to the post-commit file in the $REPOSITORY/hooks directory (see examples below)
  2. You need to enable SCM polling for the Jenkins job, but it doesn't matter what schedule you give it (you can make it as infrequent as you like, like monthly or yearly). If you disable polling, the commit hook will not trigger Jenkins builds.

I'm going to provide their example scripts to prevent link rot; I'm really only familiar with git-based repos, so I probably can't provide much assistance on these scripts themselves.

First, here's their basic example, that assumes that you have Jenkins configured with anonymous read access enabled and CSRF disabled (so it's not a very secure example at all). This would be added to the post-commit file in the $REPOSITORY/hooks directory:

REPOS="$1"
REV="$2"
UUID=`svnlook uuid $REPOS`
/usr/bin/wget \
  --header "Content-Type:text/plain;charset=UTF-8" \
  --post-data "`svnlook changed --revision $REV $REPOS`" \
  --output-document "-" \
  --timeout=2 \
  http://server/subversion/${UUID}/notifyCommit?rev=$REV

They also have a much more robust example that takes security into account:

#!/bin/sh
REPOS="$1"
REV="$2"

# No environment is passed to svn hook scripts; set paths to external tools explicitly:
WGET=/usr/bin/wget
SVNLOOK=/usr/bin/svnlook

# If your server requires authentication, it is recommended that you set up a .netrc file to store your username and password
# Better yet, since Jenkins v. 1.426, use the generated API Token in place of the password
# See https://wiki.jenkins-ci.org/display/JENKINS/Authenticating+scripted+clients
# Since no environment is passed to hook scripts, you need to set $HOME (where your .netrc lives)
# By convention, this should be the home dir of whichever user is running the svn process (i.e. apache)
HOME=/var/www/

UUID=`$SVNLOOK uuid $REPOS`
NOTIFY_URL="subversion/${UUID}/notifyCommit?rev=${REV}"
CRUMB_ISSUER_URL='crumbIssuer/api/xml?xpath=concat(//crumbRequestField,":",//crumb)'

function notifyCI {
    # URL to Hudson/Jenkins server application (with protocol, hostname, port and deployment descriptor if needed)
    CISERVER=$1

    # Check if "[X] Prevent Cross Site Request Forgery exploits" is activated
    # so we can present a valid crumb or a proper header
    HEADER="Content-Type:text/plain;charset=UTF-8"
    CRUMB=`$WGET --auth-no-challenge --output-document - ${CISERVER}/${CRUMB_ISSUER_URL}`
    if [ "$CRUMB" != "" ]; then HEADER=$CRUMB; fi

    $WGET \
        --auth-no-challenge \
        --header $HEADER \
        --post-data "`$SVNLOOK changed --revision $REV $REPOS`" \
        --output-document "-"\
        --timeout=2 \
        ${CISERVER}/${NOTIFY_URL}
}

# The code above was placed in a function so you can easily notify multiple Jenkins/Hudson servers:
notifyCI "http://myPC.company.local:8080"
notifyCI "http://jenkins.company.com:8080/jenkins"