Jenkins CI: How to trigger builds on SVN commit
You need to require only one plugin which is the Subversion plugin.
Then simply, go into Jenkins → job_name → Build Trigger section → (i) Trigger build remotely (i.e., from scripts) Authentication token: Token_name
Go to the SVN server's hooks directory, and then after fire the below commands:
cp post-commit.tmpl post-commit
chmod 777 post-commit
chown -R www-data:www-data post-commit
vi post-commit
Note: All lines should be commented Add the below line at last
Syntax (for Linux users):
/usr/bin/curl http://username:API_token@localhost:8081/job/job_name/build?token=Token_name
Syntax (for Windows user):
C:/curl_for_win/curl http://username:API_token@localhost:8081/job/job_name/build?token=Token_name
I made a tool using Python with some bash to trigger a Jenkins build. Basically you have to collect these two values from post-commit when a commit hits the SVN server:
REPOS="$1"
REV="$2"
Then you use "svnlook dirs-changed $1 -r $2" to get the path which is has just committed. Then from that you can check which repository you want to build. Imagine you have hundred of thousand of projects. You can't check the whole repository, right?
You can check out my script from GitHub.
There are two ways to go about this:
I recommend the first option initially, due to its ease of implementation. Once you mature in your build processes, switch over to the second.
Poll the repository to see if changes occurred. This might "skip" a commit if two commits come in within the same polling interval. Description of how to do so here, note the fourth screenshot where you configure on the job a "build trigger" based on polling the repository (with a crontab-like configuration).
Configure your repository to have a post-commit hook which notifies Jenkins that a build needs to start. Description of the plugin here, in the section "post-commit hooks"
The SVN Tag feature is not part of the polling, it is part of promoting the current "head" of the source code to a tag, to snapshot a build. This allows you to refer to Jenkins buid #32 as SVN tag /tags/build-32 (or something similar).