jenkins the definitive guide

(Jeff_L) #1

¶ Use regular expression processing here to extract your project name from the Subversion repository
URL.


However, this approach will only trigger one particular build, and relies on a convention that the default
build job is based on the repository name in Subversion. A more flexible approach with Subversion is
to use the Jenkins Subversion API directly, as shown here:


JENKINS_SERVER=http://myserver:8080/jenkins
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 \
$JENKINS_SERVER/subversion/${UUID}/notifyCommit?rev=$REV

This would automatically start any Jenkins build jobs monitoring this Subversion repository.


If you have activated Jenkins security, things become a little more complicated. In the simplest case
(where any user can do anything), you need to activate the “Trigger builds remotely” option (see
Figure 5.25, “Triggering a build via a URL using a token”), and provide a special string that can be
used in the URL:


http://SERVER/jenkins/job/PROJECTNAME/build?token=DOIT


Figure 5.25. Triggering a build via a URL using a token


This won’t work if users need to be logged on to trigger a build (for example, if you are using matrix
or project-based security). In this case, you will need to provide a user name and password, as shown
in the following example:


$ wget http://scott:tiger@myserver:8080/jenkins/job/gameoflife/build

or:

Free download pdf